Reputation: 63
Here is my code for connect local SQL Server with Visual Studio 2019.
SQLHANDLE sqlConnHandle = nullptr;
SQLHANDLE sqlStmtHandle = nullptr;
SQLHANDLE sqlEnvHandle = nullptr;
SQLRETURN error = 0;
if (SQL_SUCCESS != SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &sqlEnvHandle))
std::cout << "SQLAllocHandle() sqlEnvHandle error" << std::endl;
if (SQL_SUCCESS != SQLSetEnvAttr(sqlEnvHandle, SQL_ATTR_ODBC_VERSION, (SQLPOINTER*)SQL_OV_ODBC3, 0))
std::cout << "SQLSetEnvAttr() sqlEnvHandle error" << std::endl;
if (SQL_SUCCESS != SQLAllocHandle(SQL_HANDLE_DBC, sqlEnvHandle, &sqlConnHandle))
std::cout << "SQLSetEnvAttr() sqlConnHandle error" << std::endl;
std::cout << "Connecting..." << std::endl;
error = SQLDriverConnect(
sqlConnHandle,
NULL,
(SQLWCHAR*)L"Driver={SQL Server};Server=localhost\\SQLEXPRESS;Database=master;Trusted_Connection=Yes;",
SQL_NTS,
NULL,
NULL,
NULL,
SQL_DRIVER_NOPROMPT
);
It works good on 32 bit system.
When I switch to 64 bit I have error during SQLDriverConnect()
:
fetched with SQLGetDiagRec()
;
I installed 64 bit version of ODBC driver from this page: https://learn.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-ver15#download-for-windows but nothing changed.
Upvotes: 0
Views: 1743
Reputation: 63
After OBDC driver installation connection string is:
(SQLWCHAR*)L"Driver={ODBC Driver 17 for SQL Server};Server=localhost\\SQLEXPRESS;Database=master;Trusted_Connection=Yes;"
Names list of installed drivers you can find in: ODBC Data Cource Administrator -> System DSN -> Add...
Upvotes: 1
Reputation: 2055
SQL State: IM002: possible reasons
(DM) The driver listed in the data source specification in system information was not found or could not be connected to for some other reason.
On 32-bit and 64-bit Windows, the default ODBC Administrator tool is in c:\Windows\System32\odbcad32.exe. However, on a 64-bit Windows machine, the default is the 64-bit version. If the 32-bit ODBC Administrator tool is needed on a 64-bit Windows system, run the one found here: C:\Windows\SysWOW64\odbcad32.exe
Check the exact driver name in the ODBC Administrator tool. Press Windows key + R and then:
C:\Windows\System32\odbcad32.exe
on 32-bit systemsC:\Windows\SysWOW64\odbcad32.exe
on 64-bit systemsWhat is difference for connection on 32 and 64?
Upvotes: 0