Home > Back-end >  Multi-threaded database abnormal operation
Multi-threaded database abnormal operation

Time:09-23

Write a MFC client and the console server software
Run to the database operation is
The inline HRESULT Recordset15: : Close () {
HRESULT _hr=raw_Close ();
If (FAILED (_hr)) _com_issue_errorex (_hr, this __uuidof (this));
Return _hr;
Single thread no error hr=s_ok
Multithreaded hr is not normal return

What's the problem
What is is multithreaded operations database necessary requirement

CodePudding user response:

Extern CManager man;
DWORD WINAPI theProc (LPVOID p)
{
CSockLx * pSocka=(CSockLx *) p;
While (man. OnReceive (pSocka))
;
return 0;
}

Int CManager: : Start ()
{
//connect to the database if the connection fails then the pop-up error
if (! M_ado. Connect (CAdoLx: : DBT_ACCESS, _T ("./jiuye. Accdb ")))
STD: : cout & lt; <"The database connection failed." & lt;
if (! M_sock. Create (SERVER_PORT))
{
STD: : cout & lt; <"Failed to create a port:" & lt; return -1;
}
M_sock. Listen ();
WCHAR szIP [20].
UINT nPort.
//a single-threaded
/* CSockLx Socka;
Char * IP;
While (m_sock. Accept (Socka szIP, & amp; NPort))
{
IP=UnicodeToASCII (szIP);
STD: : cout & lt; While (OnReceive (& amp; Socka))
;
Socka. Close ();
} */
//multi-threaded
CSockLx * pSocka=new CSockLx;
Char * IP;
While (m_sock. Accept (* pSocka szIP, & amp; NPort))
{
IP=UnicodeToASCII (szIP);
STD: : cout & lt; CreateThread (NULL, 0, theProc pSocka, 0, NULL);
PSocka=new CSockLx;
}
return 0;
}

CodePudding user response:

Problem solved, I defined in the main function of an object, and defines an object in the global variable
Shielding the main function of CManager man object, and I have no problems that the

# include "PCH. H"
# include "CManager. H"
CManager man;

Int main ()
{
//CManager man;
Return man. Start ();
}
  • Related