简体   繁体   中英

Access violation closing the last ODBC connection (Win64 only)

I am trying to fix a problem without success related to multiple (two or more) ODBC connections with Microsoft Access driver on Windows x64 (both Windows 10 and 7). In particular, when the last connection is closed (the second one in the example), an access violation occurs (in Mso30win32client.dll module). This problem does not appear if the code is built for x86 (win32) target. I tried different compilers (C++ Builder 10.2, Visual C 2019, MingW64 4.5.3) without success. I am using the MS Access ODBC driveris installed with Office 2016 (all updates are installed) whose version is 16.00.4951.1000 (ACEODBC.DLL). If I change the data source making multiple connections with MySQL driver, the code works perfectly for both 32- and 64-bit targets.
Here is the code:

#include <windows.h>
#include <stdio.h>
#include <sql.h>
#include <sqlext.h>

#ifdef _WIN64
const TCHAR * DsnSource1 = TEXT("Driver={Microsoft Access Driver (*.mdb, *.accdb)};"
                                "Dbq=..\\..\\Ligands.mdb");

const TCHAR * DsnSource2 = TEXT("Driver={Microsoft Access Driver (*.mdb, *.accdb)};"
                                "Dbq=..\\..\\Pockets.mdb");
#else

const TCHAR * DsnSource1 = TEXT("Driver={Microsoft Access Driver (*.mdb)};"
                                "Dbq=..\\..\\Ligands.mdb");

const TCHAR * DsnSource2 = TEXT("Driver={Microsoft Access Driver (*.mdb)};"
                                "Dbq=..\\..\\Pockets.mdb");
#endif


int main(int argc, char *argv[])
{
  SQLRETURN         Res;
  HDBC              hDBC1, hDBC2;
  HENV              hEnv;

  Res = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv);
  Res = SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0);

  Res = SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &hDBC1);
  Res = SQLDriverConnect(hDBC1, NULL, (SQLTCHAR *)DsnSource1, SQL_NTS,
                         NULL, 0, NULL, SQL_DRIVER_NOPROMPT);

  Res = SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &hDBC2);
  Res = SQLDriverConnect(hDBC2, NULL, (SQLTCHAR *)DsnSource2, SQL_NTS,
                         NULL, 0, NULL, SQL_DRIVER_NOPROMPT);

  Res = SQLDisconnect(hDBC1);
  Res = SQLFreeHandle(SQL_HANDLE_DBC, hDBC1);

  Res = SQLDisconnect(hDBC2);  /* <- Access violation */
  Res = SQLFreeHandle(SQL_HANDLE_DBC, hDBC2);

  Res = SQLFreeHandle(SQL_HANDLE_ENV, hEnv);

 return 0;
}

I don't understand were is the problem. Any suggestion is appreciated and thank you in advance.

We are experiencing the same problem here using exactly this driver version and Win64. It is working now when setting "Threads=1" within the connection string, ie the dsn will be:

const TCHAR * DsnSource1 = TEXT("Driver={Microsoft Access Driver (*.mdb, *.accdb)};"
                                "Dbq=..\\..\\Ligands.mdb;Threads=1");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM