Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Why DB Pessimistic lock doesn't work

Posted on 2004-10-28
Medium Priority
Last Modified: 2010-04-01
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)};"
_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);
  m_pRS->Fields->Item["OneField"]->Value =  123;
catch (_com_error&)
  cout << "why am I'm not here ??? "<< endl;
Question by:MagicianH
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 39

Expert Comment

ID: 12435738
I would assume the exception is thrown when calling recordset Update.

Maybe for a dynamic Recordset it is different.

Regards, Alex


Author Comment

ID: 12456044
If you have a code sample that is working, maybe I coulds copy & try it out...

Author Comment

ID: 12664735
I'm interested in the answer, but nobody answers me...
LVL 39

Accepted Solution

itsmeandnobodyelse earned 500 total points
ID: 12668644
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question