SQLSTATE HY024 with error message [Microsoft][ODBC Driver Manager] Invalid argument value

290 Views Asked by At

I am trying to connect to Azure SQL via a C++ program. However it is getting failed and I found the error with SQLGetDiagRec and SQLGetDiagField. The SQLSTATE is HY024 with error message [Microsoft][ODBC Driver Manager] Invalid argument value

Below is the driver connection string I am using

    const char* cConnectString = "Driver=ODBC Driver 18 for SQL Server;Server=tcp:tmusqldev.database.windows.net,1433;Uid=tmu-admin;Pwd={PASSWORD};Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;";  

   SQLDriverConnect( // SQL_NULL_HDBC  
                    hdbc,
                    nullptr,
                    (SQLWCHAR*)cConnectString,
                    strlen(cConnectString),
                    OutConnStr,
                    255,
                    &OutConnStrLen,
                    SQL_DRIVER_PROMPT);

When I test the connection from ODBC Data Source Administrator its getting passed. I have attached screen shot for same.ODBC Data Source Administrator

Can someone suggest what might be wrong here ? I have tried by adding and removing multiple params but it has same error.

1

There are 1 best solutions below

0
On

Please try something like the following:

// Connect to the driver.  Use the connection string if supplied
// on the input, otherwise let the driver manager prompt for input.

TRYODBC(hDbc,
    SQL_HANDLE_DBC,
    SQLDriverConnect(hDbc,
                     GetDesktopWindow(),
                     pwszConnStr,
                     SQL_NTS,
                     NULL,
                     0,
                     NULL,
                     SQL_DRIVER_COMPLETE));

Here you will find a full C++ ODBC Sample to connect to Azure SQL.