473,383 Members | 1,877 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,383 software developers and data experts.

tracing sql for locks

I am fairly new to SQL Server. I am writing a tool in stored procedure
to identify locks in a table. I have already written the basic framework
of the SP. It will reside in master database and take two inputs. Database
name and table name. From that it will show all locks at that instant
on that table of that database. If table name is omitted, then it will show
locks on all tables.
I am using syslockinfo, spt_values tables and joining with SP_WHO procedure
to get the table name, user name and the session id.

Now what I need is to find out which SQL is causing the lock and since when
lock is being held on the table. Which tables in master database holds the
required information.

TIA.

Ravi
Jul 20 '05 #1
2 10395
[posted and mailed, please reply in news]

rkusenet (rk******@sympatico.ca) writes:
I am fairly new to SQL Server. I am writing a tool in stored procedure
to identify locks in a table. I have already written the basic framework
of the SP. It will reside in master database and take two inputs. Database
name and table name. From that it will show all locks at that instant
on that table of that database. If table name is omitted, then it will
show locks on all tables. I am using syslockinfo, spt_values tables and
joining with SP_WHO procedure to get the table name, user name and the
session id.

Now what I need is to find out which SQL is causing the lock and since
when lock is being held on the table. Which tables in master database
holds the required information.


That informations is not available in SQL Server.

What you can find out is:
1) The most recently submitted batch from a process, by using a DBCC
INPUTBUFFER.
2) The SQL text of the currently executing scope for a process, and
the exact current statement within that scope. To do this, you use
the function fn_get_sql(), which was added to SQL 2000 in SP3. It
is documented in the updated version of Books Online (link below),
although the text is a bit cryptic.

Note that none of these statements are necessarily those that caused
the lock, because the lock may have been acquired in a calling scope,
or even in a previous batch. What you can find, though, is the statement
that causes a process to be blocked, because if a process is blocked
and is waiting for another process to yield, then its current statement
does not change.

I have a procedure which is somewhat similar to the one you are
working with, and you can download it from my web site at
http://www.algonet.se/~sommar/sqlutil/aba_lockinfo.html. There you
can find an example on how to work with fn_get_sql().
--
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 #2
"Erland Sommarskog" <so****@algonet.se> wrote
I have a procedure which is somewhat similar to the one you are
working with, and you can download it from my web site at
http://www.algonet.se/~sommar/sqlutil/aba_lockinfo.html. There you


Yes I googled this script of your after I posted this message.

Thanks.

Ravi
--

email id is bogus
Jul 20 '05 #3

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

Similar topics

2
by: Trace User | last post by:
Hello, I have a design question regarding Tracing and Trace Switches. I understand that Trace Switches can be configured through an application's .config file. When a switch is instantiated,...
4
by: Claire | last post by:
My application runs for a while then just stops completely. No stack overflows or any other errors, visual studio doesn't report any problems. I can close the application down ok from the studio...
0
by: Paul Ibison | last post by:
HI when I have a page which calls a component I want to do the following - tracing set to false on the pag tracing set to true in the componen tracing set to false in the page after the call to...
6
by: serge calderara | last post by:
Dear all, I have an applicatin that generate a querry to an SQL server, then display results on a second webform. I try to see how tracing works, then I have notice that as soon as I...
2
by: deepukutty | last post by:
Hi all, I know tht we can do tracing in two ways.one in application level and the other is at Page level. I am able to see the details of trace either on the page itself or .../trace.axd page....
0
by: cnys | last post by:
We have an ASP.NET 2.0 (C#) app and we're trying to add tracing into it. The tracing functionality within .NET is great, but when we output this to a file, it's kind of sparse. So, we're looking...
0
by: rehto | last post by:
We have an ASP.NET 2.0 (C#) app and we want to enable tracing (see the code snippets below). The first time a user navigates to the app., the tracing works fine (the ASP.NET tracing appears on...
1
by: BAS | last post by:
Guys, Assume i have taken the db2pd -locks output and there i have seen lockesculations like this +898 0x42D14020 37 000E28090028A5020000000052 Row .NS W
4
by: Michel Esber | last post by:
Environment: DB2 v8 LUW FP 15 running on Linux. For some reason that I canīt explain, a simple insert statement on a table may run very quickly, or may take forever (20-30mins) to finish....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.