Solved

a Process locked a table (SQL 2000)

Posted on 2010-08-24
7
696 Views
Last Modified: 2012-08-13
I have a SQL Server 2000 database that when the users came in Monday morning a table was locked and my users couldn't use my application.  This application with the SQL backend database has been around for 9 years and we have never had this problem.  The user who locked the table (who was off Monday) was the new computer guy for the department and he was admittedly playing with the database so he could become familiar with it.  Note the computer guy is not a SQL Server person and was not writing procs but might have been doing queries or playing with the data in the table.

My questions
* I don’t understand how “a process” could lock a table.  By locking a table (my terminology) the particular table if opened in Enterprise Manager would time out and not show any records.  What I’m looking for is a couple of  “SIMPLE” examples of how to lock a table so it would time out.

* I had to go through the DBA who I was lucky enough she wanted to work with me.  Once we determined the problem she “Stopped the process” and all was fine.  How do I see a locking process in Enterprise Manager 2000 and then stop it.  (I don’t have the rights to Enterprise Manager on the live db but I would like to see it on my local copy  [I manage the live db through an Access adp])

A little more info:
I'm a programmer that uses SQL Server but my expertise is with the front end not the backend.
0
Comment
Question by:LJG
  • 3
  • 3
7 Comments
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 33511691
>> Note the computer guy is not a SQL Server person and was not writing procs but might have been doing queries or playing with the data in the table.

Did he opened up any Transaction using those tables and have closed it properly.
If he didn't closed it, then that might cause the table to get locked till the transaction is closed out.
0
 
LVL 8

Expert Comment

by:Mohit Vijay
ID: 33511766
use WITH (NOLOCK) when you trying to fetch record from a table (SELECT Query from table)
0
 
LVL 2

Author Comment

by:LJG
ID: 33511858
rrjegan17 my problem is that I'm not sure what he did, but I'm sure he didn't write any procedures that used transaction, but he might of linked to the table with Access.  Is it possible he added a record maybe, then did a delete query and didn't complete it (Access would ask are you sure you want to delete).  He got interrupted and never answered OK?

Would this have locked the table from Friday to Monday?

Thanks for your help.
LJG
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 500 total points
ID: 33521732
>> Is it possible he added a record maybe, then did a delete query and didn't complete it (Access would ask are you sure you want to delete).  He got interrupted and never answered OK?

Yes, it can definitely.
what I meant above was similar ( Modifying records within a transaction and not committed it).

Can you check whether any active transactions are running in the server using the below query:

SELECT *
FROM sys.dm_tran_active_transactions
0
 
LVL 2

Author Comment

by:LJG
ID: 33533336
If a table is locked in SQL 2000 - Here are some thoughts.

0) Create the below view :
    SELECT     master.dbo.sysprocesses.spid, master.dbo.sysdatabases.name AS db_name, master.dbo.sysprocesses.hostname AS MachineName,
                          master.dbo.sysprocesses.nt_domain, master.dbo.sysprocesses.nt_username, master.dbo.sysprocesses.cmd, master.dbo.sysprocesses.blocked,
                          master.dbo.sysprocesses.login_time, master.dbo.sysprocesses.last_batch, master.dbo.sysprocesses.status, master.dbo.sysprocesses.dbid,
                          master.dbo.sysprocesses.open_tran, master.dbo.sysprocesses.program_name, master.dbo.sysprocesses.hostprocess
    FROM         master.dbo.sysprocesses INNER JOIN
                          master.dbo.sysdatabases ON master.dbo.sysprocesses.dbid = master.dbo.sysdatabases.dbid
    WHERE     (master.dbo.sysprocesses.dbid = 10) AND (master.dbo.sysprocesses.open_tran > 0)



1) Run the above view and get the SPID that is causing the problem.

2) Run --> sp_Lock  with the SPID  from above on the end --> eg -->  sp_Lock 54
     Get the ObjId

3) Run SELECT object_name(with the above ObjId)  eg -->
    Use Your Database Name
    SELECT object_name(1298871744)

4) You now know Who, Where, and What Object is Locked.

5) Kill the Process  -->   Kill with SPID  on the end eg --> KILL 54

6) You are good to go

7)  You might also want to look at --> DBCC OPENTRAN WITH TABLERESULTS


Hope this helps someone.
LJG
0
 
LVL 2

Author Closing Comment

by:LJG
ID: 33533371
rrjegan17 -
You gave me the answer to what was locking the database - was able to confirm that truely lockes the table.

Also a great place to start on finding and unlocking such locks even though

SELECT *
FROM sys.dm_tran_active_transactions

does not work in SQL 2000 I was able to find some other solutions.  If someone is interested to my post below.

Thanks again
LJG
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 33542769
>> does not work in SQL 2000 I was able to find some other solutions.  If someone is interested to my post below

In SQL Server 2000, approach mentioned in your comment would hold good with few modifications.(simplifying the query)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

747 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

16 Experts available now in Live!

Get 1:1 Help Now