简体   繁体   中英

regsvr32 causes CDatabase destrucor to hang when using SQL Native Client (v2005)

I've got a C++ COM dll in Visual Studio 2005 that uses SQL Server (v2000) driver to connect to the database (SQL Server 2005). We've recently been tasked by our DB Team to upgrade our SQL Server driver from SQL Server (v2000) to SQL Native Client (v2005) or SQL Server Native Client 10.0 (v2007).

Application builds just fine. Then, when I go to perform the regsvr32 command on the DLL to register it for COM, the application hangs. When I debugged through the code I found that in the InitInstance of the main APP (which inherits from CWinApp) the application logs a startup message to the database using a stored procedure.

Debugging into that logging message reveals that a CDatabase object is created which executes the stored procedure. The stored procedure executes correctly; the message gets logged to the database and execution is returned to the C++ code. Then, when the CDatabase object is closed (by calling CDatabase::Close()) the application hangs. I debugged into the CDatabase code and found that in CDatabase::Close() a call is made to

AFX_SQL_SYNC(::SQLFreeConnect(m_hdbc));

It's in this call that the execution does not return. The debugger goes back to a (Running) state and nothing comes back. When I try and do a Debug -> Break All I get a message stating that there are no running threads and that the process may be deadlocked.

This only happens during the call to REGSVR32. And if I choose the Sql Server driver for the regsvr32 portion, then change it to the Sql Native Client or Sql Server Native Client v10.0 the application works just fine.

I'm working with Microsoft on this as well, but we're running out of time. Any help or thoughts would be greatly apprecaited!

Thanks,

The guy in the link below seem to have solved it by dynamically loading the ODBC dlls in his main APP and not only in the DLL. Could this be somehow applicable in your case?

SQLFreeHandle Deadlock Issue?

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