Solved

Forcing a table lock in SQL Server 2000

Posted on 2010-08-12
4
400 Views
Last Modified: 2012-05-10
We are testing a program change that locks a table when it updates.  There can be multiple requests for this update and we have error handling that does this.  We want to test this functionality before we move it to Production, but I'm having a hard time finding a way to force a table lock so that we can test the error processing.  I have seen a way through bcp, but I'd prefer not to do it that way.  In the query, we are locking using a Transaction and the TABLOCK and HOLDLOCK hints.  This is in SQL Server 2000 accessed through vb.net.

Thanks
0
Comment
Question by:dgoncher
[X]
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
4 Comments
 
LVL 3

Expert Comment

by:yanoch
ID: 33423187
In your vb app, start a transaction
Then select * from your table
Then sleep // do your tests
Then rollback
0
 

Author Comment

by:dgoncher
ID: 33432378
"In your vb app, start a transaction
Then select * from your table
Then sleep // do your tests
Then rollback"

This did not work.  I started a transaction in vb.net did the select * and a sleep for a minute.  While it was sleeping, I ran the other program which reads then updates the record and it successfully read and updated.

Any other ideas?
0
 
LVL 3

Accepted Solution

by:
yanoch earned 500 total points
ID: 33433250
Just by writing the following in your sql console it will lock from updating :
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
BEGIN TRANSACTION
select * from youtable

when you want to remove the transaction
COMMIT TRANSACTION

0
 

Author Closing Comment

by:dgoncher
ID: 33433371
This worked thanks.  If anyone else has this issue, make sure you turn off the option in Query Analyzer that disconnects after query executes before you run the SQL.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

615 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