Article ID: 148726
Article Last Modified on 1/6/2000
136885 OLE Threads Must Dispatch Messages
void doit()
{
RETCODE rc; /* Return code for ODBC functions */
HENV henv; /* Environment handle */
HDBC hdbc; /* Connection handle */
HSTMT hstmt; /* Statement handle */
//variables
unsigned char connStrOut[256];
MSG msg;
HANDLE myhandle;
myhandle = GetCurrentThread();
//Allocate ODBC handles and make the connection to the database
SQLAllocEnv(&henv);
rc = SQLAllocConnect(henv, &hdbc);
rc = SQLDriverConnect(hdbc, 0,(unsigned char *)"DSN=hello", SQL_NTS,
connStrOut, 256, NULL,
SQL_DRIVER_NOPROMPT);
//Handle messages to prevent other OLE applications from hanging
MsgWaitForMultipleObjects( 1, &myhandle, FALSE, INFINITE,QS_ALLINPUT);
AfxMessageBox("type in something",MB_OK);
//Disconnect and free the ODBC handles
SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
SQLFreeEnv(henv);
ExitThread(0);
}
void CTestMultiThread::OnTest()
{
HANDLE hTestThread;
DWORD dwThreadID ;
hTestThread = CreateThread((LPSECURITY_ATTRIBUTES)NULL,0,
(LPTHREAD_START_ROUTINE)doit,this,0,&dwThreadID);
return;
}
NOTE: With the ODBC Desktop Database Drivers 2.0 running on Windows NT 3.5,
only one thread can make a SQLConnect or SQLDriverConnect call. Other
threads in the same application cannot make the connection calls at any
time while the application is running. Once a connection is made on a
thread, the connection (hdbc) can be shared by other threads. This is
because OLE did not support multithreading in Windows NT 3.5.
Keywords: KB148726