I need help! I program in C++ with MFC and using the CRecordset class.
My problem is I use the Requery() function about 10 times a second during heavy use. After about a hour of this heavy use, the Requery() function stops working; all of the previous Re-querys that worked, no longer works! After about 15 minutes of this error, my program crashes. Has anybody heard of this problem?
Compiled in winXP (32 bit) and windows7 (64bit) with the same results. This error is found to occur in more than 5 computers with MS Access (2003) or SQL (2005). The only thing common is the MSVS2005
I got a free copy of MSVC2005 from Microsoft for taking one of their online courses many years ago; it is a full featured standard edition of Visual Studio 2005.
Does anybody have any clues?
I have 4 threads accessing one function (the problem function) where it funnels down to a shared resource, the database. I use a semaphore so that the "read only" Requery is used one-at-time. One of the fields is a CLongBinary where it holds one picture info to be displayed on the screen when Re-queryied.
sorry about some of the format below, paste but came out different and hand edit to make it readable; hopefully
Below are some code snippets.
ViewClass.cpp
THE REQUERY:
if(m_pCardSet->IsOpen())
{
m_pCardSet->m_MyParam = 1;
m_pCardSet->m_nParams = 1;
m_pCardSet->m_strCardNoParam = CardNo;
m_pCardSet->m_strFilter = "CardNo = ?";
m_pCardSet->Requery();
if(m_pCardSet->IsEOF() && m_pCardSet->IsBOF())
{
p = CardDBQue.RemoveHead();
n = InterlockedDecrement(&CardDBCount);
return(_T("NO ENTRIES IN CARDHOLDER DATABASE"));
} if( (int)m_pCardSet->m_Image.m_dwDataLength < 100 )
HAS_PIX = FALSE;
else
HAS_PIX = TRUE;
if(HAS_PIX == TRUE)
if(CreateStreamOnHGlobal(NULL, TRUE, &pStream) == S_OK)
{
LPVOID buffer = GlobalLock(m_pCardSet->m_Image.m_hData);
pStream->Write(buffer, (UINT)m_pCardSet->m_Image.m_dwDataLength, ulWritten);
GlobalUnlock(m_pCardSet->m_Image.m_hData);
}
..... etc.
THE m_pCardSet CLASS: (Standard setup)
class CCardHolderSet : public CRecordset
{
public:
CCardHolderSet(CDatabase* pDatabase = NULL);
DECLARE_DYNAMIC(CCardHolderSet)
CDBpwd m_dbParam;
CStringA m_CardNo; BOOL m_AntiPass; CStringA m_FirstName; CStringA m_LastName; CStringA m_TransCode; CLongBinary m_Image; CStringA m_ImageName; BOOL m_Voided; CStringA m_SecLevel;
CStringA m_strCardNoParam;
int m_MyParam; public:
virtual CString GetDefaultConnect();
virtual CString GetDefaultSQL(); virtual void DoFieldExchange(CFieldExchange* pFX); #ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
};
IMPLEMENTAION OF THE CLASS ABOVE:
CCardHolderSet::CCardHolderSet(CDatabase* pdb)
: CRecordset(pdb)
{
m_CardNo = _T("");
m_AntiPass = 0;
m_LastName = _T("");
m_FirstName = _T("");
m_TransCode = _T("");
m_ImageName = _T("");
m_Image.m_hData = 0;
m_Voided = FALSE;
m_SecLevel = _T("");
m_nFields = 9;
m_nDefaultType = ConnectType;
m_strCardNoParam = _T("");
m_MyParam = 0;
m_nParams = 0;
}
CString CCardHolderSet::GetDefaultConnect()
{
CString Dsn;
Dsn.Format("%s%s%s", m_dbParam.DbString,m_dbParam.DbParamStr, m_dbParam.DbLogonStr);
return(Dsn);
}
CString CCardHolderSet::GetDefaultSQL()
{
if(CONNECT_SQL_DB == TRUE)
return _T("[dbo].[CardHolder]");
else
return _T("[CardHolder]");
}
void CCardHolderSet::DoFieldExchange(CFieldExchange* pFX)
{
pFX->SetFieldType(CFieldExchange::outputColumn);
RFX_Text(pFX, _T("[CardNo]"), m_CardNo);
RFX_Bool(pFX, _T("[AntiPass]"), m_AntiPass);
RFX_Text(pFX, _T("[FirstName]"), m_FirstName);
RFX_Text(pFX, _T("[LastName]"), m_LastName);
RFX_Text(pFX, _T("[TransCode]"), m_TransCode);
RFX_Text(pFX, _T("[ImageName]"), m_ImageName); RFX_LongBinary(pFX, _T("[Image]"), m_Image);
RFX_Bool(pFX, _T("[Voided]"), m_Voided);
RFX_Text(pFX, _T("[SecLevel]"), m_SecLevel, 63999);
switch(m_MyParam)
{
case 1:
pFX->SetFieldType(CFieldExchange::param);
RFX_Text(pFX, "CardNo", m_strCardNoParam);
break;
default:
break;
}
}
Craig C.