BUG: S1000 Error When Sharing Connection in Multiple Threads

Last reviewed: December 9, 1997
Article ID: Q175313
The information in this article applies to:
  • Microsoft Visual C++, 32-bit Editions, version 5.0

SYMPTOMS

When sharing a CDatabase object between multiple threads and using the SQL Server ODBC driver version 2.65.0240 or later, the following error occurs:

   SQLSTATE: S1000
   [Microsoft][ODBC SQL Server Driver]Connection is busy with the results
   for another hstmt

CAUSE

This error occurs because of a timing conflict in the SQL Server ODBC driver. If two threads are in the process of calling SQLPrepare(), followed by a SQLExecute() call, this error may occur.

RESOLUTION

Put CRecordset::Open() calls within a critical section to guarantee that only one thread is executing a SQL command on the connection at a given time.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft SQL Server driver. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Following is a code sample that can cause this error to occur:

   void CDBProblemDlg::OnDoDatabase()
   {
      //Open connection to database
      m_DB.Open();
      CSQLRecordSet rs(&m_DB);

      StartThread(&m_DB);

      if ( rs.Open(CRecordset::dynaset) )
      {
          .
          .
          .
          SQLRecordSet.Close();
      }
   }

      void StartThread(CDatabase * pDB)
   {
      AfxBeginThread(InitThreadProc, pDB, THREAD_PRIORITY_NORMAL);
   }

   UINT CDBProblemDlg::InitThreadProc( LPVOID pParam )
   {
      CDatabase* pDB = (CDatabase*) pParam;
      if (pDB->IsOpen())
      {
         CSQLRecordSet SQLRecordSet(pDB);

         if (SQLRecordSet.Open(CRecordset::dynaset))
         {
            .
            .
            .
            SQLRecordSet.Close();
         }
      }
   }


Additional query words: VC++
Keywords : MfcDatabase
Technology : odbc
Version : WINNT:5.0
Platform : winnt
Issue type : kbbug


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 9, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.