DBOTMA
asked on
Child Windows Freeze on large SQL query
I have a C++ MDI application using MFC with SQLServer. The sql query is complex and takes approximately 20 sec to complete. This freezes the application and the user can't do any thing in the other child windows. I would like to know what should be done to allow the user to continue on the other Child windows while the sql query retrieves its information.
A snip of my code:
CDatabase m_db;
Interface::Interface()
{
m_db.OpenEx("DSN=MYsql;Des cription=t est;APP=Mi crosoft\x0 0ae Visual Studio .NET;WSID=TEST;DATABASE=my DB;Trusted _Connectio n=Yes");
}
CMyRecView.h
-----------------
class CMyRecView : public CRecordView
{
protected:
CMyRecView();
..
..
}
CMyRecView.cpp
-----------------
void CMyRecView::OnBnClickedReq uest()
{
CDynamicBulkSet rs(&m_db);
rs.Open(CRecordset::snapsh ot, "SELECT * FROM tblLeaders", CRecordset::readOnly | CRecordset::useMultiRowFet ch);
FillGrid(&rs);
rs.Close();
}
Many Thanks,
Dan
A snip of my code:
CDatabase m_db;
Interface::Interface()
{
m_db.OpenEx("DSN=MYsql;Des
}
CMyRecView.h
-----------------
class CMyRecView : public CRecordView
{
protected:
CMyRecView();
..
..
}
CMyRecView.cpp
-----------------
void CMyRecView::OnBnClickedReq
{
CDynamicBulkSet rs(&m_db);
rs.Open(CRecordset::snapsh
FillGrid(&rs);
rs.Close();
}
Many Thanks,
Dan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The problem is not with FillGrid, even with the line commented out it still take 20 seconds.
Please note: The sql "select * from tblLeaders" is only to show the problem.
Any better solutions than using a worker thread?
Please note: The sql "select * from tblLeaders" is only to show the problem.
Any better solutions than using a worker thread?
void CYourClass::FillGrid(CReco
{
MSG msg;
(******* LOOP *******)
{
while ( ::PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE) )
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
m_wndYourList.InsertItem(.
}
Good LUck