Connection string failure with SQL Server ODBC connection

Igor Korot 26 Reputation points
2025-01-13T17:25:54.02+00:00

Hi, ALL,

I have weird problem as follows:

In my program I use SQLDriverConnect() to connect to the SQL Server.

Before this call I modify the connection string in order to use MARS.

I set up DSN and if everything is good, meaning I run the program and I enter the correct password, everything works fine..

However if I make a mistake with the password and enter the correct one on the second try - the program behaves as if the connection string was not modified and no MARS support is turned on.

Is this a known problem? If it is - I presume its from the driver itself and not from the SQLDriverConnect() API, right?

Thank you.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,290 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,823 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. LiHongMSFT-4306 29,826 Reputation points
    2025-01-14T08:29:42.57+00:00

    Hi @Igor Korot

    Check the explanation from this doc: Driver Guidelines

    Based on the value of DriverCompletion, the driver prompts the user for connection information, such as the user ID and password, and connects to the data source:

    • SQL_DRIVER_PROMPT: The driver displays a dialog box, using the values from the connection string and system information (if any) as initial values. When the user exits the dialog box, the driver connects to the data source. It also constructs a connection string from the value of the DSN or DRIVER keyword in *InConnectionString and the information returned from the dialog box. It places this connection string in the *OutConnectionString buffer.
    • SQL_DRIVER_COMPLETE or SQL_DRIVER_COMPLETE_REQUIRED: If the connection string contains enough information, and that information is correct, the driver connects to the data source and copies *InConnectionString to *OutConnectionString. If any information is missing or incorrect, the driver takes the same actions as it does when DriverCompletion is SQL_DRIVER_PROMPT, except that if DriverCompletion is SQL_DRIVER_COMPLETE_REQUIRED, the driver disables the controls for any information not required to connect to the data source.

    Best regards,

    Cosmog


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.