ODBC Driver Manager memory corruption on call to SQLDriverConnect



I am building an ODBC Driver for Microsoft Windows XP. I am getting memory
corruption during a call from the application to SQLDriverConnect(). I
observe the following:
1. The application allocates an environment handle (provided by the Driver
Manager);
2. The application allocates a connection handle (provided by the Driver
Manager);
3. The application calls SQLSetEnvAttr with SQL_ATTR_ODBC_VERSION as 2;
4. The application calls SQLDriverConnect() with appropriate arguments;
5. The Driver Manager calls my driver to allocate an environment handle
which I return;
6. The Driver Manager calls my driver to set the ODBC version to 2 (and
passes in the correct environment handle created in step #5);
7. The Driver Manager calls my driver to allocate a connection handle (and
passes in the correct environment handle created in step #5) which I return;
8. The Driver Manager calls my driver to query the driver ODBC version
string (and passes in the correct environment handle created in step #5) and
I return "03.52";
9. At this point things become a bit fuzzy. It appears that the Driver
Manager decides to abandon the connection attempt--my SQLDriverConnect()
function is never called--and the Driver Manager modifies its copy of the
driver environment handle;
10. The Driver Manager calls my driver to free the connection handle (and
passes in the correct connection handle allocated in step #7);
11. The Driver Manager calls my driver to free the environment handle--and
passes in a bad value;
12. When my driver attempts to free the environment handle the Driver
Manager provides, the memory manager reports this as a corrupt pointer.

I assume that there is something missing from or wrong with my driver, but I
can't see what it might be--or why such an error would prompt the Driver
Manager to corrupt memory. Calls to SQLConnect() do not suffer the same fate.
I'm logging all entrypoints in my driver, and these are the only calls the
Driver Manager makes.
.



Relevant Pages

  • RE: [dbi] DBD::ODBC, unixODBC, FreeTDS, MS-SQL, lazy DL, dbd_db_login/SQLSetConnectOption err=-2
    ... manager but when it was passed to another ODBC API it got through to the driver ... in unixODBC driver manager and handle returned. ... Perl using lazy linking for loading ODBC.so ...
    (perl.dbi.users)
  • Re: documention on connstring
    ... The syntax is driver dependent, since each driver is free to parse the ... connection as seen fit. ... The driver manager only recognizes a few options ... SQLDriverConnect describes the manager and SQL Driver keywords: ...
    (microsoft.public.fox.programmer.exchange)
  • Re: ODBC32.DLL access violation during DriverConnect
    ... suggest you open a support incident with Product Support (the VC++ database ... The function VFreeErrors is an internal function that free's up all the ODBC ... So for example your driver could be passing an error structure to ODBC from ... How can I figure out what the Driver Manager is doing? ...
    (microsoft.public.data.odbc)
  • ODBC32.DLL access violation during DriverConnect
    ... SQLAllocHandle() is called with SQL_HANDLE_ENV; ... How can I figure out what the Driver Manager is doing? ... Following is the Driver Manager trace output: ...
    (microsoft.public.data.odbc)
  • ODBC connectivity
    ... [ODBC Driver Manager] ... "Microsoft OLE DB Provider for ODBC Drivers ...
    (microsoft.public.inetserver.iis)