Solved

Why DB Pessimistic lock doesn't work

Posted on 2004-10-28
229 Views
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)};"
            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;
}
0
Question by:MagicianH
    4 Comments
     
    LVL 39

    Expert Comment

    by:itsmeandnobodyelse
    I would assume the exception is thrown when calling recordset Update.

    Maybe for a dynamic Recordset it is different.

    Regards, Alex

    0
     

    Author Comment

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

    Author Comment

    by:MagicianH
    I'm interested in the answer, but nobody answers me...
    0
     
    LVL 39

    Accepted Solution

    by:
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
    C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    846 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now