473,412 Members | 3,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Locking Users Out of Table

SQL Server 2000, MSDE 2000

I have a procedure in my application that I would like only one user at a
time to be able to run. Is there a TSQL command I can run that will
esentially lock a set of tables so others cannot access the table until the
user is done with the procedure or until the user disconnects from that
session (in case of a hung app, I would like to lock released)

TIA

--
Tim Morrison

----------------------------------------------------------------------------
----

Vehicle Web Studio - The easiest way to create and maintain your vehicle
related website.
http://www.vehiclewebstudio.com
Jul 20 '05 #1
3 4710

"Tim Morrison" <sa***@kjmsoftware.com> wrote in message
news:uGvSb.184669$I06.2024103@attbi_s01...
SQL Server 2000, MSDE 2000

I have a procedure in my application that I would like only one user at a
time to be able to run. Is there a TSQL command I can run that will
esentially lock a set of tables so others cannot access the table until the user is done with the procedure or until the user disconnects from that
session (in case of a hung app, I would like to lock released)

TIA

--
Tim Morrison

-------------------------------------------------------------------------- -- ----

Vehicle Web Studio - The easiest way to create and maintain your vehicle
related website.
http://www.vehiclewebstudio.com


One possibility is to use an application lock - see sp_getapplock and
sp_releaseapplock in Books Online - which your procedure would attempt to
acquire before continuing. Alternatively, you can use a table column as a
flag to indicate whether or not the procedure is already running, but in
this case you have to handle the case of dropped connections yourself.

Simon
Jul 20 '05 #2
Start a transaction, do a select top 1 * from my_table with (tablockx).
Should keep out everyone except those that do "with (nolock)" dirty reads
until your transaction is committed or rolled back. A global var used in the
SP can be used to flag that it is already running.

"Tim Morrison" <sa***@kjmsoftware.com> wrote in message
news:uGvSb.184669$I06.2024103@attbi_s01...
SQL Server 2000, MSDE 2000

I have a procedure in my application that I would like only one user at a
time to be able to run. Is there a TSQL command I can run that will
esentially lock a set of tables so others cannot access the table until the user is done with the procedure or until the user disconnects from that
session (in case of a hung app, I would like to lock released)

TIA

--
Tim Morrison

-------------------------------------------------------------------------- -- ----

Vehicle Web Studio - The easiest way to create and maintain your vehicle
related website.
http://www.vehiclewebstudio.com

Jul 20 '05 #3
Tim Morrison (sa***@kjmsoftware.com) writes:
I have a procedure in my application that I would like only one user at
a time to be able to run. Is there a TSQL command I can run that will
esentially lock a set of tables so others cannot access the table until
the user is done with the procedure or until the user disconnects from
that session (in case of a hung app, I would like to lock released)


First you need to decide. Is it this particular procedure that you
want to serialize, or do you want to lock out any access to the tables?

Simon suggested application locks, and I think this is the best, as
this can be restricted to the procedure alone. The best is to have
a transaction enclosed, so that when you commit or rollback the lock
is released. But if don't want to have the entire procedure within
a transaction, or want to have several transactions, you can also take
out an application lock on session level.

For more details, look up sp_getapplock in Books Online.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ryan | last post by:
I have a problem with record locking / blocking within an application. The app is quite straight forward. Written in Delphi 5 using BDE to access a SQL 7 database (Win2K server). Every so often...
9
by: john smile | last post by:
Hi All, I want to lock 2 tables on 2 servers using TABLOCKX hint. These tables function as semaphores in my application. It means when the tables are locked then other users will not be able to...
4
by: Sam | last post by:
Hello everyone, I have around 20 reports in an ASP web-application which connects to a SQL Server 2000 dB, executes stored procedures based on input parameters and returns the data in a nice...
16
by: Nid | last post by:
How do I do row-level locking on SQL Server? Thanks, Nid
1
by: David McGeorge | last post by:
Dear Gurus, A Client has the following problems/requests for their Production databases, what is your professional/practical advises to tackle and resolve these issues: 1)Number of...
2
by: Scott Bryce | last post by:
I am creating a CGI application in Perl that uses an Access database. It will be hosted on an NT server. I have used flat file DBMs (tied hashes) on UNIX servers, but I am not familiar with how...
6
by: MS | last post by:
Access 97 here. I want a simple way to "lock" certain records on a form. Some records remain "live" until all data is available which happens over time. When all the fields are complete, I want...
5
by: swapna_munukoti | last post by:
Hi all, Is there any tool to achieve record locking in MS Access 2000. Thanks, Swapna.
0
by: Cindy Huyser | last post by:
I have an Access 2000 database behind a threaded Java application that that can have have concurrent access to the same table (but not the same record). The database is set up for shared access...
7
dlite922
by: dlite922 | last post by:
I need to do some sort of Locking mechanism at interface level, instead of DB Level. I know how MySQL table locking works, but that won't work in my scenerio. Requirements: When someone is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.