The best way to use worker thread to connect to an database
-
What is the best way to connect an database through an worker thread ? I teach from here[^] how to use an worker thread ... Ok , but in worker thread I use theApp global member variable which have an database connection ... but the problem is that not every time thread unconnect database or destroy theApp.m_pDB member variable from CMyApp::ExitInstance() event .... I don't know why ?! So , can you tell me how to connect to an database from an worker thread ? Thank you !
-
What is the best way to connect an database through an worker thread ? I teach from here[^] how to use an worker thread ... Ok , but in worker thread I use theApp global member variable which have an database connection ... but the problem is that not every time thread unconnect database or destroy theApp.m_pDB member variable from CMyApp::ExitInstance() event .... I don't know why ?! So , can you tell me how to connect to an database from an worker thread ? Thank you !
mesajflaviu wrote:
So , can you tell me how to connect to an database from an worker thread ?
I would be inclined to connect to the database in the primary thread, and then pass the
CDatabase
pointer to the secondary thread."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
mesajflaviu wrote:
So , can you tell me how to connect to an database from an worker thread ?
I would be inclined to connect to the database in the primary thread, and then pass the
CDatabase
pointer to the secondary thread."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
Connection to database I make in primary thread ... and now , since I discover threads :D , I try to switch connection to an worker thread ... Ok , I have connection attach it to global theApp variable ... ex : theApp.ExecuteSQL(...) , theApp.GetData(...) , etc. so , you say to pass this varaible ( theApp ) as parameter to worker thread ? Since theApp is global variable , what is the point ?
-
Connection to database I make in primary thread ... and now , since I discover threads :D , I try to switch connection to an worker thread ... Ok , I have connection attach it to global theApp variable ... ex : theApp.ExecuteSQL(...) , theApp.GetData(...) , etc. so , you say to pass this varaible ( theApp ) as parameter to worker thread ? Since theApp is global variable , what is the point ?
mesajflaviu wrote:
so , you say to pass this varaible ( theApp ) as parameter to worker thread
Not what I said at all.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
mesajflaviu wrote:
so , you say to pass this varaible ( theApp ) as parameter to worker thread
Not what I said at all.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
Then , to pass theApp.m_pDB ( CDatabase* kind of ) like parameter to worker thread ?