Script: Get Inputbuffer For Spid's Holding Locks

Jul 20, 2002

Here's a quick script that will return the inputbuffer of processes that are holding more than a certain threshold of locks (by default, 10, but it's easy to modify). Handy for tracking down what query is holding those 1400 locks.

Yes, it uses a cursor. I'd welcome amendment by anyone who has the insight on converting it to pure set-based.

Cheers
-b

CREATE PROCEDURE sp_lock4 AS
set nocount on

DECLARE @tSpids table(spid int PRIMARY KEY CLUSTERED,count int)
DECLARE @iSpid int,@iCount int

insert into @tSpids (spid,count)
select convert (smallint, req_spid) As spid,
count(*) as count

from master.dbo.syslockinfo,
master.dbo.spt_values v,
master.dbo.spt_values x,
master.dbo.spt_values u

where master.dbo.syslockinfo.rsc_type = v.number
and v.type = 'LR'
and master.dbo.syslockinfo.req_status = x.number
and x.type = 'LS'
and master.dbo.syslockinfo.req_mode + 1 = u.number
and u.type = 'L'
group by converT(smallint,req_spid),'dbcc inputbuffer(' + cast(req_spid as varchar(4)) + ')'
having count(*)>10
order by count(*) desc

DECLARE cLoop cursor for
select spid,count from @tSpids

OPEN cLoop

FETCH NEXT FROM cLoop INTO @iSpid,@iCount
WHILE @@FETCH_STATUS=0
BEGIN
select 'spid ' + cast(@iSpid as varchar(4)) + ' has ' + cast(@iCount as varchar(5)) + ' locks.'
exec ("dbcc inputbuffer (" + @ispid + ")")
FETCH NEXT FROM cLoop INTO @iSpid,@iCount
END

CLOSE cLoop
DEALLOCATE cLoop

return (0) -- sp_lock
GO

View 1 Replies


ADVERTISEMENT

SQL Server Admin 2014 :: SPID Causing Locks With No Query Text Shown

Oct 1, 2015

I just ran into an issue with cascading locks due to a SPID on one of my production servers. When researching the lock, I noticed that there was no sql text. SP_Who 2, nor the following query captured anything,

SELECT sqltext.TEXT
, sqlplan.query_plan
, req.session_id
, req.status
, req.command

[Code] ....

I spoke to the user causing the lock and he ran into a visual basic error when this occurred and didn't close out that window. So my guess is that it's due to an uncommitted transaction. However, shouldn't I still see something if that was the case?

View 4 Replies View Related

SQL Server 2008 :: Row Locks Not Escalating To Table Locks After 5000

Jul 16, 2015

I've got an INSERT that's selecting data from a linked server and attempting to push 10 million rows into the blank table. More or less, it looks like this:

insert into ReceivingTable (
Field1, Field2, Field3, Field4
, Field5, Field6, Field7, Field8
, Field9, Field10, Field11, Field12
, Field13, Field14, Field15

[code]...

The instance of the SQL Server Database Engine cannot obtain a LOCK resource at this time. Rerun your statement when there are fewer active users. Ask the database administrator to check the lock and memory configuration for this instance, or to check for long-running transactions. There are no other active users. I ran it again and monitored the following DMO to watch the growth of locks for that spid:

SELECT request_session_id, COUNT (*) num_locks
-- select *
FROM sys.dm_tran_locks
--where request_session_id = 77
GROUP BY request_session_id
ORDER BY count (*) DESC

The number of locks started small and held for a while around 4-7 locks, but at about 5 minutes in the number of locks held by that spid grew dramatically to more than 8 million before finally erroring again with the same message. Researching, I can't figure out why it's not escalating from row locks to table locks at the appropriate threshold. The threshold in was set to 0 at first (Server Properties > Advanced > Parallelism > Locks). I set it to 5000, and it still didn't seem to work. Rewriting the INSERT to include a WITH (TABLOCK) allows it to finish successfully in testing. My problem is that it's coming out of an ETL with source code that I can't edit. I need to figure out how to force it to escalate to locking the entire table via table or server level settings.

A colleague suggested that installing service packs may take care of it (the client is running SQL Server 2008 R2 (RTM)), but I haven't found anything online to support that theory.

View 9 Replies View Related

Transact SQL :: How To List All Locks (including NON-BLOCKING Locks)

Aug 5, 2015

We are migrating our database(s) from ORACLE to SQL. In Oracle we were able to issue a SELECT statement and see all of the locks (Blocking and Non-Blocking) currently in the system.  The query also included the Process ID of the process we needed to kill in order to get rid of the lock.

We now need to create the same type of query for Microsoft SQL Server 2012. I have seen postings on different sites saying that this info can be obtained using SP_WHO2 or using the SQL Server Management Studio Activity Monitor's PROCESSES tab, but we are looking for a SELECT statement that will give us similar information.

View 7 Replies View Related

DBCC INPUTBUFFER

Jun 13, 2002

if the inputbuffer contains more than 256 chars, it only reports out the first 256 characters of the buffer. that's because EventInfo is defined as a nvarchar(256) field.

is there any way to get the full inputbuffer...even if it's more than 256 chars? i'm trying to run this:

exec mn @parameter_number_1 = 'abcdefghijklmnopqrstuvwxyz',
@parameter_number_2 = 'abcdefghijklmnopqrstuvwxyz',
@parameter_number_3 = 'abcdefghijklmnopqrstuvwxyz',
@parameter_number_4 = 'abcdefghijklmnopqrstuvwxyz',
@parameter_number_5 = 'abcdefghijklmnopqrstuvwxyz',
@parameter_number_6 = 'abcdefghijklmnopqrstuvwxyz',
@parameter_number_7 = 'abcdefghijklmnopqrstuvwxyz',
@parameter_number_8 = 'abcdefghijklmnopqrstuvwxyz',
@parameter_number_9 = 'abcdefghijklmnopqrstuvwxyz',
@parameter_number_10 = 'abcdefghijklmnopqrstuvwxyz'

and all i get is this:

EventType Parameters EventInfo
--------- ---------- -----------------------------
Language Event 0 exec mn @parameter_number_1 = 'abcdefghijklmnopqrstuvwxyz',
@parameter_number_2 = 'abcdefghijklmnopqrstuvwxyz',
@parameter_number_3 = 'abcdefghijklmnopqrstuvwxyz',
@parameter_number_4 = 'abcdefghijklmnopqrstuvwxyz',
@parameter_number_5 = 'abcdefghijkl

is there any way to get the entire input buffer?

Thanks in advance,
mike

View 2 Replies View Related

Greater Inputbuffer?

Aug 9, 2001

I'm trying to sniff or view a fairly large query that get's passed to my sql server.

The problem I'm having is that the dbcc inputbuffer only shows the first 255 chars of query and I need to see the whole thing.

Is there another method or a way to increase the size of this so I can see the whole query?

Thanks

- jeff

View 3 Replies View Related

Dbcc Inputbuffer

Oct 15, 2004

Hi folks.
DBCC INPUTBUFFER(79)
the statement returned is too short, not full. Can i get full STATEMENT that is sent by the user.

Howdy!

View 5 Replies View Related

DBCC Inputbuffer

Dec 24, 2007

Does anyone know if there is an equivalent way to get to the information that DBCC Inputbuffer returns using 2005s dynamic management objects? sys.dm_exec_requests only returns information that is currently executing...as DBCC inptubuffer returns the last statement executed for a session.

Thanks,
Tim

View 8 Replies View Related

Dbcc Inputbuffer Lock

Jan 14, 2000

We are running a Windows NT Terminal server 4.0 with SQL 7. The application we are using has two main connections to the database that may at times update the same table simultaneously. On two seperate occasions we have run into a lock that causes these processes to hang. They appear to still be running in the Task Manager, but have no CPU time. When we review the current activity on the SQL server under Object/locks one of the items listed is "tempdb.dbo.##lockinfo13(the spid)". The last TSQL command batch is "dbcc inputbuffer(13). We have tried to research what this dbcc inputbuffer does, and why there is a conflic here... but have come up empty. Can you help with any information on this dbcc?

View 2 Replies View Related

Store The DBCC InputBuffer Result

Jul 5, 2001

Hello,

I must get the content of dbcc inputbuffer (nn).
The structure of the result is well described in the BOL.

However, I don't find a way to store the result in temporary table or other stuff.
Thanks in advance.
Regards
Patrick

View 2 Replies View Related

DBCC INPUTBUFFER Results Into Table

May 10, 2007

Does anyone know if there is a simple way to get the results of a DBCCINPUTBUFFER() request into a table? I have a process for monitoringactivity that will give me the results of sp_who2 into a temp table,and want to scroll through the active connections and get the inputbuffers into another table for review:Insert into #TmpWhoexec sp_who2 'active'Something like that with the dbcc command.I am using SQL 2000 SP4.Thanks,Tom

View 3 Replies View Related

Alternative To DBCC INPUTBUFFER/sys.dm_exec_sql_text?

Feb 19, 2008

Thanks for the help everyone.

Updated versions of the proc and view can be found here for now: http://www.sqlservercentral.com/Forums/Topic457115-146-1.aspx

View 10 Replies View Related

Need Hand Holding

Oct 7, 2007

Hi -
Is there a resource I can go to that lists people who I pay to talk me through stuff like getting SQL Server Express installed, get some sample data input and then get that data into Excel? I just cannot seem to get any help that works for me to learn SQL Server; the books are obtuse, the online help too indirect. Once I get something working I hope to enhance it on my own, but I have been stuck at the start for a very long time. There is stuff for me to do that is not getting done.

Doug

View 1 Replies View Related

Linking Sysprocesses To Results Of DBCC Inputbuffer

May 23, 2008

Guys,
I need to send a group of people a list of specific processes running on the server, one of the requirements is to send them what's actually being ran on the machine. I have the information I was on the sysprocess tabke and the results of the DBCC Inputbuffer. Is there a way to link both result sets?

This is the criteria of the processes that neeed to be sent out to my users:

SELECT *
FROM master.dbo.sysprocesses p
WHERE last_batch < DATEADD(mi, -5, GETDATE())
AND dbo.fncGetNumLocks(p.spid, DB_ID('EngDataMart')) > 1
GROUP BY p.spid, p.loginame, p.hostname, dbo.fncGetNumLocks(p.spid, db_id('DBName'))
ORDER BY p.spid

Thanks,

View 1 Replies View Related

Variables Holding Filename

Feb 8, 2007

I already posted this question in the Wrong Forum.

However I was wondering if it is possible to create a variable that holds the filename as an expression. I am using a For each loop to pick up files and i want to insert the 'Filename' as a colum so that i can differentiate among the rows in my destination Table.

Using the 'Derived Colum' in DTS I can link the colum to the variable. However i do not know how to create the variable which will store the filename for each file....

Any Clues...
Would really appreciate the help.....

View 2 Replies View Related

SQL Configuration Holding Connections To DS

May 27, 2006

Hello All,

I have about 160 packages in my system, all using about 20 shared datasources.
When changing one of the datasource's connection (changing the server name), I need to open every one of my packages and press OK to allow the remapping to the new server. (this is something I don't understand: wasn't this the meaning of using a share datasource in the first place? what's the advantages in that case?)

So, I have heard about Package configuration, and how it supposed to support all of this, But I don't understand something: The configuration is set to a certain package. If I have 2 packages, using the same two (of four) Datasources. Using the configuration wizard from one of the packages, I mark the connection string from the datasource. I need to do the same in the other package? will the configuration table hold only one value for that connection? If I change the value of the connection string will it affect all the packages using that datasource or only the ones using configuration?

Thanks,



Liran

View 10 Replies View Related

Variable Not Holding Value For Select Statement

Dec 7, 2005

this querry below works perfect when i assign the us.UserID = 29 but i need to be able to use the @UsersMaxID variable..... when i debug all of my values are right where they need to be... even this on (((   @UsersMaxID  ))) but for some reason it will not work with the next select statement...
 
can someone make the pain go away and help me here..??
 
erik..
 
GOSET ANSI_NULLS ON GO
ALTER  PROCEDURE AA
ASDECLARE @GenericColumn Varchar (200) DECLARE @GenericValue Varchar (200)
SET @GenericColumn = 'FirstName'SET @GenericValue = 'Erik'
 DECLARE @SQL NVARCHAR(4000)  DECLARE @UserID INT  DECLARE @UsersMaxID INT  DECLARE @MaxID INT
declare @tempResult varchar (1000)
-------------------------------------------Define the #Temporary Table----------------------------------------------CREATE TABLE #UsersTempTable ( ID int IDENTITY PRIMARY KEY,
UserID [int], FirstName [varchar](30), LastName [varchar](30), CompanyName [varchar](200), Address1 [varchar](75), Address2 [varchar](75), City [varchar](75),ActiveInd [int], Zip [varchar](10), WkPhone [varchar](12),HmPhone [varchar](12), Fax [varchar](12), Email [varchar](200), Website [varchar](200), UserType [varchar](20),Title [varchar](100),Note [text], StateCD [char](2), CountryCD [char](2), CompanyPhoto [varchar](50), CompanyDescr [varchar](2000)) ---------------------------------------Fill the temp table with the Customers data-----------------------------------SET @SQL = 'INSERT INTO #UsersTempTable (UserID, FirstName, LastName, CompanyName, Address1, Address2, City, ActiveInd, Zip, WkPhone, HmPhone,Fax, Email, Website, UserType, Title, Note, StateCD, CountryCD, CompanyPhoto, CompanyDescr)
Select Users.UserID, Users.FirstName,Users.LastName, Users.CompanyName, Users.Address1, Users.Address2, Users.City, Users.ActiveInd, Users.Zip, Users.WkPhone, Users.HmPhone,Users.Fax,Users.Email,Users.Website, Users.UserType,Users.Title, Users.Note,Users.StateCD, Users.CountryCD,Users.CompanyPhoto,Users.CompanyDescr
FROM USERS
 WHERE ' + @GenericColumn +' = ''' + @GenericValue  + ''''
EXEC sp_executesql @SQL
SET @MaxID = (SELECT MAX(ID) FROM #UsersTempTable)SET @UsersMaxID = (SELECT UserID From #UsersTempTable WHERE ID = @MaxID)
SELECT SpecialtyName FROM Specialty s                           INNER JOIN UserSpecialty us                           ON s.SpecialtyCD = us.SpecialtyCD                           WHERE us.UserID = 29
SELECT * FROM #UsersTempTable
 
 ==========================================================================================SET @UsersMaxID = (SELECT UserID From #UsersTempTable WHERE ID = @MaxID)
SELECT SpecialtyName FROM Specialty s                           INNER JOIN UserSpecialty us                           ON s.SpecialtyCD = us.SpecialtyCD                           WHERE us.UserID = 29 <<<<<<<<<<<<<<<<< i need @UserMaxID ........RIGHT HERE

View 1 Replies View Related

T-SQL (SS2K8) :: Changes Not Holding In Stored Procedure

Apr 8, 2014

I am connecting to a new SQL Server 2008 R2 database using SSMS from my ADMIN VM workstation. I bring up a Stored Procedure and make a change.... I execute the Stored Procedure... after it finishes.... I exit out without saving to a file.... I go back in and my change was not held.

I can do the exact same process with an old SQL Server 2005 database. Is there a permission I am missing to set to be able to do this on the 2008 database.

View 9 Replies View Related

Return Name Of Column Holding Highest Value

Apr 25, 2008

I have this query that returns the largest value in a row, but i need to know the column name that this value is in as well. any help in advance is appreciated

select clientID,
(select max(incomeValue)
from
(select earnings as incomeValue
union all
select unemployment
union all
select pensionRetirement
union all
select alimony
union all
select childSupport
union all
select dividendInterest
union all
select SS
union all
select SSI
union all
select SSDI
union all
select veteranBenefits
union all
select FIP
union all
select workStudy
union all
select other
union all
select otherHHWS) as income) as MaxIncomeValue
from tbl_income

View 12 Replies View Related

Who Is Holding A Database Backup-file?

Jun 23, 2007

I don't know where to post this kind of stuff so here goes...



I have maintenance plans which sometimes fail because the delete step reports that the old backup file is "in use." I have no idea how to determine what Windows thinks is holding the file. HOw do you determine who is holding a file hostage??



Thanks.

View 3 Replies View Related

Process Being Freed While Holding Dataserver Semaphore

Feb 25, 1999

Warning: Process Being Freed While Holding Dataserver Semaphore

I understand that this is a bug. And that it is supposed to be fixed in
service pack 4.
However, has anyone experienced or figured out how to get rid of this message?

Thanks for your help.

View 1 Replies View Related

Database Design Question - Holding Additional Data

Oct 1, 2007

I've done some basic database design in the past, but am a relative newbie to design. I have recently come across a situation I'm not sure how to handle. Here's the situation...

Assume we've got a contacts table which holds information about our contacts. All contacts have the same basic information - name, address, telephone, etc. Each contact is of a certain type - let's just say a, b, and c, for ease. This contact type is stored in the contacts table. Now, on contacts of type b, I also have to store some additional data. What it is doesn't really matter. I found a way to set this up, but I'm not sure that I'm going about it the right way, and would love some advice on the proper way to do this. Basically, what I did is create my contacts table:
Contact_id, contactName, ContactAddress, ContactPhone, ContactType.
Created a contacttype table
ContactType, ContactTypeDescription, ContactAddInfo

What I've done is left contactaddInfo as a nullable field. When it has a value, that value is the name of a table which holds the additional information that I need for the contact... So when I'm running a query, I can tell if I need to reference another table by checking the value of ContactAddInfo.

I can't imagine that this is the best solution, but it was the first thing that popped into my head, and it's a really small database that's using it. However, I'm now being faced with the same situation in a much more important, larger database, and I'd love to know the 'right' way.

Thanks for any guidance you can provide!
Erin

View 4 Replies View Related

SQL Server 2008 :: Rows Holding Group-wise Maximum Of Certain Column?

May 13, 2015

is there any more efficient way for example to implement the next query?

SELECT s1.article, dealer, s1.price
FROM shop s1
JOIN (
SELECT article, MAX(price) AS price
FROM shop
GROUP BY article) AS s2
ON s1.article = s2.article AND s1.price = s2.price;
WHERE dealer = 'dealer sample'

What indexes I should create for this query?

View 2 Replies View Related

Reporting Services :: Design Pattern For Holding Back Subscriptions When ETL Hasn't Completed

Jun 19, 2015

I'm working on an application that allows users to set up scheduled time based reports. Each scheduled report creates a SQL Agent job associated with a schedule.The default time to fire these off is 8:00 AM. There are several hundred. DWH and it has no trouble running hundreds of reports all fired off at the same time.

There are several ETL processes and occasionally they don't complete before our verbal SLA of 8:00 AM.

My problem is on days where the ETL runs past 8:00 AM I wan't to hold these scheduled jobs from firing off.

View 4 Replies View Related

Spid

Dec 14, 2000

Could someome please tell me what is going on with the following stored procedure:

EXECUTE msdb.dbo.sp_sqlagent_get_perf_counters

View 1 Replies View Related

Spid

Dec 13, 2005

HI!
if i have SPID. then can i get the storedprocedure name ?

Regards,
Shabber Abbas Rizvi.

View 1 Replies View Related

See The SQL For A Spid

Mar 28, 2006

All,

Is there any way to see the SQL for any given spid in SQL server?

I can see "properties" under enterprise mgr - which shows you a snippet of the SQL - or "sp_execute" depending on what you use to get to the DBMS.

Is there a way to take a deeper look?

Thanks,

Isaac

View 2 Replies View Related

Value Of @@SPID

Apr 15, 2004

Hi,

Can I have more than one value for variable @@SPID during a connection?

PS: sorry my english.

Thanks.

View 3 Replies View Related

Spid

May 18, 2004

Hi All,
Sql Server 7.

I have a table cust_detail when ever there is an insert/update/delete in this table it is getting blocked and in turn its blocking other table inv_credit which is doing select statement.

Please suggest me what might be the reason.

Waiting for Reply
TIA
Adil

View 1 Replies View Related

Spid

Jun 19, 2008

Hi to all.

I have a small doubt.
In my server some processs are running slow.
With out the use of profiler hw we can find the spid's that are running slow. is there any procedure for that.

View 5 Replies View Related

SPID In Blk By Is Itself

Dec 29, 2006

I am seeing intermittent blocking problems. The strange part of it is,that the SPID listed in the Blk By column is the same as the SPID thatis being blocked.Has anyone seen this before, or have any idea what this may suggest?

View 1 Replies View Related

Spid Info

May 12, 2000

Hi,
Here i have a question..
Whenever i see my spid in LOCK/PROCESS ID
one command DBCC BUFFERINPUT(MY SPID) always running
and it is showing ''''tempdb.dbo.##lockinfo'''
MODE---- X
Is it pretty normal or something wrong..
i am not running any thing, just simply opened EM..
Pls any suggestions...
thank u

kavira

View 2 Replies View Related

Spid - Blocking

Nov 15, 2000

I know that spid 22 is blocking 2 other users. How do I tell who that user is? Is this just matching the same spid# in the process info in EM and if it doesn't give me an NT name it's probably because they're coming through the application and I can't figure it out?

Thanks

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved