Link to home
Start Free TrialLog in
Avatar of sniles
sniles

asked on

AFX_SQL_ERROR_LOCK_MODE_NOT_SUPPORTED thrown for PESSIMISTIC locking in Access

I'm using VC++ 5.0, MFC and ODBC (to Access 2000). I'm trying to issue a CRecordset SetLockingMode( pessimistic ).  MFC is throwing AFX_SQL_ERROR_LOCK_MODE_NOT_SUPPORTED.

Opening my CRecordset with Open( CRecordset::dynaset, NULL, CRecordset::none);

How can I set pessimistic without getting this exception?
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

I'd make sure your up to date on the MDAC stuff.  2.5 is the current release.  I'd try an update on that first.  

 Be aware though that I'm suggesting this only as a first troublshooting step and don't know if it will address the problem or not.

Jim.

Avatar of sniles
sniles

ASKER

Thanks. I'm already running MDAC 2.5
Alright, I'll do a little digging and see what I come up with....
Jim.
I dug around a bit and it looks like one of two things:

1. The recordset is not updateable.

2. The ODBC driver your using does not support pessimistic locking.

  I found this note at the bottom of some C++ documentation:

"Note   Relatively few ODBC drivers currently support pessimistic locking."

  Unfortunatly, they didn't say which ones do.  Is it possible for you to switch to the DAO classes?

Jim.
Avatar of sniles

ASKER

The recordset is updateable.  You 2nd point could well be the reason.  Here is the code that is generating the exception (in CRecordset class):
if (nLockMode == pessimistic)
{
RETCODE nRetCode;
UDWORD dwTypes;
SWORD nResult;
AFX_SQL_SYNC(::SQLGetInfo(m_pDatabase->m_hdbc, SQL_LOCK_TYPES,
      &dwTypes, sizeof(dwTypes), &nResult));
if (!Check(nRetCode) || !(dwTypes & SQL_LCK_EXCLUSIVE))
ThrowDBException(AFX_SQL_ERROR_LOCK_MODE_NOT_SUPPORTED);
      }

.... I stepped through this, and the nRetCode is not 0, so it's the second clause that's causing the failure. This makes your #2 item listed above the likely cause: Access doesn't support pessimistic locking (although I can't find anything at Microsoft's Knowledgebase that states this).

Regarding DAO: I'm unfamiliar with DAO, and am curious about the amount of work/change to switch to it, and what other issues it raises (i.e., DBMS compatibility, installation issues). Do you know a good article that covers this topic?
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sniles

ASKER

That's ok.  I only meant if you happened to know of one off the top of your head -- didn't mean to send you on a quest.  I've since found some information on DAO & ODBC that should get me launched in the right direction.

Thanks very much for your help.