Why DB Pessimistic lock doesn't work

I have code that changes a field in pessimistic lock.
I'm loading two instances of visual C++ with the same code.
in theory when I'm trying to change a field in the same record, I'm supposed
to get an exception, for some reason it doesn't work.
does anyone knows does this happen ?

The code is like this:

m_pDBConn->ConnectionString = _bstr_t( L"DRIVER={Microsoft Access Driver (*.mdb)};"
            L"DBQ=MyDB.mdb;DefaultDir=m:/DB/;");       
_bstr_t bsEmpty = L"";
m_pDBConn->Open( bsEmpty, bsEmpty, bsEmpty, -1 );
hr = m_pRS.CreateInstance(__uuidof(Recordset));
m_pRS->PutRefActiveConnection( m_pDBConn );
m_pTempRS->Open("SELECT * FROM MyTable WHERE ID = 1", vtMissing, adOpenKeyset, adLockPessimistic, adCmdText);
try
{
  m_pRS->Fields->Item["OneField"]->Value =  123;
}
catch (_com_error&)
{
  cout << "why am I'm not here ??? "<< endl;
}
MagicianHAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
itsmeandnobodyelseConnect With a Mentor Commented:
You asked for a code sample. Unfortunately, i didn't use ADO myself, so i couldn't provide a sample.

However, i'am a pretty experienced database programmer. So, i wouldn't expect 'Pessimistic Locking' is throwing an exception when editing members of the recordset

   m_pRS->Fields->Item["OneField"]->Value =  123; // It's a simple integer assignment

- as that is C++ and the database or recordset isn't involved .

I would expect an exception when you are trying to store while another client had updated in the meantime.

Maybe you should check that suggestion using your own code.

Regards, Alex
0
 
itsmeandnobodyelseCommented:
I would assume the exception is thrown when calling recordset Update.

Maybe for a dynamic Recordset it is different.

Regards, Alex

0
 
MagicianHAuthor Commented:
If you have a code sample that is working, maybe I coulds copy & try it out...
0
 
MagicianHAuthor Commented:
I'm interested in the answer, but nobody answers me...
0
All Courses

From novice to tech pro — start learning today.