dbTalk Databases Forums  

SQLS 2000 Record Locking Problems (VC++)

microsoft.public.sqlserver.odbc microsoft.public.sqlserver.odbc


Discuss SQLS 2000 Record Locking Problems (VC++) in the microsoft.public.sqlserver.odbc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Arnie
 
Posts: n/a

Default SQLS 2000 Record Locking Problems (VC++) - 04-07-2006 , 03:26 PM






Sorry for the wordiness.

VC++ 8.0, XP Pro SP2, etc. We're porting from Borland C++
Builder/ADO to VC++/ODBC. This worked fine with BCB/ADO.

First, the rationale. We have a number of 'batch' (console) apps
that can not be run at the same time due to possible conflicts in
DB tables. The apps can be run on a number of different servers,
and they all access the same DB, so named semaphores were out.
We were using a DB table as a semaphore. The idea was to insert
a row in the table with the name of a table that should be
'logically' locked. The locked table name column name is unique.
We don't actually want to lock the table itself because other
read only programs should be able to use the table.

I'm sorry if that isn't crystal clear. Here's the problem. I
put together a test program in order to determine the problem.
Very simply,

- Set up the hEnv and hDbc stuff.
- Execute "SET LOCK_TIMEOUT 2000"
- Set SQL_AUTO_COMMIT_OFF
- Execute the INSERT statement
- Wait for keyboard input

Run the program. Fine. Run another instance and it 'hangs' on
the INSERT. Where's my timeout? The second instance won't "come
back" until the first instance terminates.

Thanks for any help,
- Arnie





Reply With Quote
  #2  
Old   
privatenews
 
Posts: n/a

Default RE: SQLS 2000 Record Locking Problems (VC++) - 04-09-2006 , 10:01 PM






Hello Arnie,

When Auto_commit is set to off, all executed statements are included in the
same transaction until it is specifically terminated by calling SQLEndTran.
It seems you wait keyboard during the transaction which is not recommended.
This will lock the record with exclusive lock and it will not release
before transaction is committed. You could run sp_lock and check
sysprocesses for details.

With lock timeout set, the blocked statement is canceled automatically, and
error message 1222 "Lock request time-out period exceeded" is returned to
the application.

However, any transaction containing the statement is not rolled back or
canceled by SQL Server. Therefore, the application must have an error
handler that can trap error message 1222. If an application does not trap
the error, it can proceed unaware that an individual statement within a
transaction has been canceled, and errors can occur because statements
later in the transaction may depend on the statement that was never
executed.

Please run sql profiler to captuer the errors/locks informaiton to see if
you could see the timeout message.

Best Regards,

Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

================================================== ===


This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
Quote:
From: "Arnie" <99yoda (AT) newsgroup (DOT) nospam
Subject: SQLS 2000 Record Locking Problems (VC++)
Date: Fri, 7 Apr 2006 16:26:04 -0400
Lines: 35
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Original
Message-ID: <ugnfPFoWGHA.1348 (AT) TK2MSFTNGP05 (DOT) phx.gbl
Newsgroups: microsoft.public.sqlserver.odbc
NNTP-Posting-Host: 24-151-53-204.dhcp.nwtn.ct.charter.com 24.151.53.204
Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFT NGP05.phx.gbl
Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.sqlserver.odbc:44877
X-Tomcat-NG: microsoft.public.sqlserver.odbc

Sorry for the wordiness.

VC++ 8.0, XP Pro SP2, etc. We're porting from Borland C++
Builder/ADO to VC++/ODBC. This worked fine with BCB/ADO.

First, the rationale. We have a number of 'batch' (console) apps
that can not be run at the same time due to possible conflicts in
DB tables. The apps can be run on a number of different servers,
and they all access the same DB, so named semaphores were out.
We were using a DB table as a semaphore. The idea was to insert
a row in the table with the name of a table that should be
'logically' locked. The locked table name column name is unique.
We don't actually want to lock the table itself because other
read only programs should be able to use the table.

I'm sorry if that isn't crystal clear. Here's the problem. I
put together a test program in order to determine the problem.
Very simply,

- Set up the hEnv and hDbc stuff.
- Execute "SET LOCK_TIMEOUT 2000"
- Set SQL_AUTO_COMMIT_OFF
- Execute the INSERT statement
- Wait for keyboard input

Run the program. Fine. Run another instance and it 'hangs' on
the INSERT. Where's my timeout? The second instance won't "come
back" until the first instance terminates.

Thanks for any help,
- Arnie







Reply With Quote
  #3  
Old   
Arnie
 
Posts: n/a

Default Re: SQLS 2000 Record Locking Problems (VC++) - 04-10-2006 , 08:14 AM



Thanks for your reply.

Waiting for keyboard input is only done in the test program. It
is done so that I can run the second instance of the program to
see what happens when it tries to insert an identical record.

The problem is that the second instance 'hangs' on the SQLExecute
that attempts the insert. Therefore, there is no return code.
If I allow the first instance to complete, then the second
instance returns from the SQLExecute with, as expected, a unique
constraint violation.

My question is: Why doesn't the second instance time out? Does
the lock timeout value apply to all SQL statements or just to a
SELECT?

Thanks,
- Arnie



Reply With Quote
  #4  
Old   
privatenews
 
Posts: n/a

Default Re: SQLS 2000 Record Locking Problems (VC++) - 04-11-2006 , 01:01 AM



Hello Arnie,

Did you check the @error varialbe? You may want to use the steps in the
following KB to check if you could get the lock timeout error in Query
Analyzer

FIX: LOCK_TIMEOUT causes transaction to roll back and @@error does not
capture error 1222
http://support.microsoft.com/kb/q286286/

Regards,

Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

================================================== ===


This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
Quote:
From: "Arnie" <99yoda (AT) newsgroup (DOT) nospam
References: <ugnfPFoWGHA.1348 (AT) TK2MSFTNGP05 (DOT) phx.gbl
3ZrASsEXGHA.888 (AT) TK2MSFTNGXA01 (DOT) phx.gbl
Subject: Re: SQLS 2000 Record Locking Problems (VC++)
Date: Mon, 10 Apr 2006 09:14:11 -0400
Lines: 20
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
Message-ID: <uAMQ5BKXGHA.3800 (AT) TK2MSFTNGP03 (DOT) phx.gbl
Newsgroups: microsoft.public.sqlserver.odbc
NNTP-Posting-Host: 24-151-53-204.dhcp.nwtn.ct.charter.com 24.151.53.204
Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP01.phx.gbl!TK2MSFT NGP03.phx.gbl
Xref: TK2MSFTNGXA01.phx.gbl microsoft.public.sqlserver.odbc:44881
X-Tomcat-NG: microsoft.public.sqlserver.odbc

Thanks for your reply.

Waiting for keyboard input is only done in the test program. It
is done so that I can run the second instance of the program to
see what happens when it tries to insert an identical record.

The problem is that the second instance 'hangs' on the SQLExecute
that attempts the insert. Therefore, there is no return code.
If I allow the first instance to complete, then the second
instance returns from the SQLExecute with, as expected, a unique
constraint violation.

My question is: Why doesn't the second instance time out? Does
the lock timeout value apply to all SQL statements or just to a
SELECT?

Thanks,
- Arnie





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.