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.
Can someone suggest what might be wrong here ? I have tried by adding and removing multiple params but it has same error.
Please try something like the following:
Here you will find a full C++ ODBC Sample to connect to Azure SQL.