SetLockingMode(CRecordset::pessimistic) gives me a Runtime Error

SetLockingMode(CRecordset::pessimistic) gives me a Runtime Error

Post by Jorge Rodr » Sat, 16 Aug 2003 05:46:36


Hi! I am bulding a c++ program that read data from a files
a put it into a Database (ACCESS or MS SQL Server) via an
ODBC connection, the problem I got is that the program
runs in several conputers at the same time and access the
same database, so when more that two computers access the
same record for edit/update I got a afx22 error, and the
system crahes, so I have been trying to lock the record
but when I use the SetLockingMode
(CRecordset::pessimistic), I got a run time error,

any Ideas:

Thanks

This is my code with the problem

if (!ScriptStatsTable.IsOpen())
{
try
{
ScriptStatsTable.SetLockingMode
(CRecordset::pessimistic);
ScriptStatsTable.Open();
}
catch (CDBException* pEx)
{
CString strMessage(_T("Could not open
ScriptStats Table: "));
strMessage += pEx->m_strError;
printf("\n%s\n",strMessage);
strcopyC(strMessage,output);
write2file(error,output);
write2file(error,"\r");
write2file(error,"\n");
IsDBok = 0;
}
}

try
{
ScriptStatsTable.Edit();
}
catch (CDBException* pEx)
{
CString strMessage(_T
("Could not Edit Script Stats Table: "));
strMessage += pEx-
printf("\n%
s\n",strMessage);
strcopyC
(strMessage,output);
write2file(error,output);
write2file(error,"\r");
write2file(error,"\n");
}
}
switch (codeno)
{
case 50 : {

ScriptStatsTable.m_Counter =
ScriptStatsTable.m_Counter + minutes;
break;
}
case 97 : {
minutes =
atoi(ipaddress);

ScriptStatsTable.m_Counter =
ScriptStatsTable.m_Counter + minutes -1;
break;
}
case 98 : {
minutes =
atoi(ipaddress);

ScriptStatsTable.m_Counter =
ScriptStatsTable.m_Counter + minutes;
break;
}
default: {

ScriptStatsTable.m_Counter =
ScriptStatsTable.m_Counter + 1;
break;
}
}
int isnotokeyyet = 0;
while (isnotokeyyet == 0)
{
try
{

ScriptStatsTable.m_pDatabase-
Sleep(10);
ScriptStatsTable.m_pDatabase-
Sleep(10);
ScriptStatsTable.m_pDatabase-
Sleep(10);
ScriptStatsTable.Update();
isnotokeyyet = 1;
}
catch (CDBException* pEx)
{
CString strMessage(_T("Could not
UPDATE Script Stats Table: "));
strMessage += pEx->m_strError;
printf("\n%s\n",strMessage);
strcopyC(strMessage,output);
write2file(error,output);
write2file(error,"\r");
write2file(error,"\n");
Sleep(1000);
if (strMessage.Find("locked by
user",0) != -1)
{
Sleep(2000);
}
}
}
 
 
 

1. CRecordset::SetLockingMode() function

2. SetLockMode(CRecordSet::pessimistic)

Dear All

Please help in finding out what I'm doing wrong
I'm trying to lock a record on SQL server using ODBC connectio
in a chosen table.
I define a sql query string. Then I open a query usin
Open api on my CRecordset object (say oRS
then accrding to recommedation of MSDN on setLockMod
I'm tring to execute

oRS.SetLockMode(CRecordset::pessimistic)

and then locking would be to execut

oRS.Edit()

Unfortunatelly I got an exception from
oRS.SetLockMode(CRecordset::pessimistic)
with an errorCode 1012 and a message "Requested lock mode
is not supported""

Can anyone explain me why is it so? Is it possible that SQL server
ODBC drive doesn't support such a mode of locking. Or rather
am I doing something wrong

Any help appreciate
Greeting
Mare

3. CRecordset not writing record nor giving errors on some XP Build 5.1 SP2

4. CRecordset Giving Error while Featching Data form MS Access Memo Field

5. CRecordset not writing record nor giving errors on some XP Build 5.1 SP2

6. File Save Dialog gives RunTime Error 445

7. Update query giving runtime error 3417 action query cannot be used

8. Excel help giving runtime error

9. Mod and Int gives me a Runtime Error 13 -- Type mismatch.

10. Name of shape giving VB run-time error

11. textbox.curline=0 gives runtime error -2147418113