Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 transaction was deadlocked

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2010-09-13 : 09:49:22
every time i run a specific query i get
Msg 1205, Level 13, State 45, Line 1
Transaction (Process ID 60) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.


what does this error mean and why would i always get it when running a specific query.

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-09-13 : 10:03:56
It means that there is another process with a higher cost that is deadlocking your query.

You should post the query first.

Does this happen in production or when you run in management studio?

There are many scripts to see what's running on the box at the moment here's a sample one:

/* Jobs Details for a specific db (works on 2000 and 2005)
**
** Charlie (19/02/2008)
** Modified (11/06/2008)
*/

-- ==== Configuration =========================================================

DECLARE @dbName VARCHAR(50) SET @dbName = '<< YOUR DATABASE NAME HERE >>'

-- ==== ------------- =========================================================

USE MASTER
SET NOCOUNT ON

IF object_Id('tempdb..#spwho') IS NOT NULL DROP TABLE #spwho
IF object_Id('tempdb..#info') IS NOT NULL DROP TABLE #info
IF object_Id('tempdb..#dbccInput') IS NOT NULL DROP TABLE #dbccInput

DECLARE
@spid INT
, @sqlHandle BINARY(20)
, @sqlVersion INT

-- Which version of SQL server are we running.
SET @sqlVersion = CASE
WHEN @@VERSION LIKE '%2005 - 9.%' THEN 2005
WHEN @@VERSION LIKE '%2000 - 8.%' THEN 2000
END

CREATE TABLE #spWho (
[SPID] INT NOT NULL
, [Status] VARCHAR (255) NOT NULL
, [Login] VARCHAR (255) NOT NULL
, [HostName] VARCHAR (255) NOT NULL
, [BlkBy] VARCHAR(10) NOT NULL
, [DBName] VARCHAR (255) NULL
, [Command] VARCHAR (255) NOT NULL
, [CPUTime] INT NOT NULL
, [DiskIO] INT NOT NULL
, [LastBatch] VARCHAR (255) NOT NULL
, [ProgramName] VARCHAR (255) NOT NULL
, [SPID2] INT NOT NULL
)

-- Add a column if it's 2005
IF @sqlVersion = 2005 ALTER TABLE #spWho ADD [REQUESTID] INT NOT NULL DEFAULT 0

CREATE TABLE #dbccInput (
eventType NVARCHAR(30)
, paramaters INT
, eventInfo NVARCHAR(4000)
)

CREATE TABLE #info (
[spid] INT NOT NULL
, [status] VARCHAR(20) NOT NULL
, [login] VARCHAR(255) NOT NULL
, [blkBy] VARCHAR(10) NOT NULL
, [command] VARCHAR(255) NOT NULL
, [CPUTime] INT NOT NULL
, [DiskIO] INT NOT NULL
, [LastBatch] VARCHAR (255) NOT NULL
, [ProgramName] VARCHAR (255) NOT NULL
, [sqlHandle] BINARY(20) NULL
, [eventInfo] NVARCHAR(4000) NULL
, [sql] TEXT NULL
)

INSERT INTO #spWho EXEC sp_who2

-- Get basic job info for the database we are intersted in
INSERT INTO #info (
[spid]
, [status]
, [login]
, [blkBy]
, [command]
, [CPUTime]
, [DiskIO]
, [LastBatch]
, [ProgramName]
, [sqlHandle]
)
SELECT
sw.[spid]
, sw.[status]
, sw.[login]
, sw.[blkBy]
, sw.[command]
, sw.[CPUTime]
, sw.[diskIO]
, sw.[lastBatch]
, sw.[programName]
, sp.[sql_handle]
FROM
#spWho sw
JOIN master.dbo.sysprocesses sp ON sp.[spid] = sw.[spid]
WHERE
[DBName] = @dbName

-- Get the sql info for each spid
DECLARE sqlCursor CURSOR LOCAL READ_ONLY FOR
SELECT
i.[spid]
, i.[sqlHandle]
FROM
#info i

OPEN sqlCursor

FETCH NEXT FROM sqlCursor INTO
@spid
, @sqlHandle

WHILE (@@fetch_status = 0) BEGIN

INSERT INTO #dbccInput
EXEC ('DBCC INPUTBUFFER(' + @spid + ')')

UPDATE #info
SET
[eventInfo] = dbccI.[eventInfo]
FROM
#dbccInput dbccI
WHERE
[spid] = @spid

-- clear the input info
TRUNCATE TABLE #dbccInput

-- Get the sql full text (only does currently running process)
UPDATE #info
SET
[sql] = fgs.[text]
FROM
::fn_get_sql(@sqlHandle) fgs
WHERE
[spid] = @spid

FETCH NEXT FROM sqlCursor INTO
@spid
, @sqlHandle

END

CLOSE sqlCursor
DEALLOCATE sqlCursor

-- Display the results
SELECT
[spid]
, [status]
, [login]
, [blkBy]
, [command]
, [CPUTime]
, [DiskIO]
, [LastBatch]
, [ProgramName]
, [eventInfo] AS lastEvent
, [sql] AS currentSql
FROM
#info

IF object_Id('tempdb..#spwho') IS NOT NULL DROP TABLE #spwho
IF object_Id('tempdb..#info') IS NOT NULL DROP TABLE #info
IF object_Id('tempdb..#dbccInput') IS NOT NULL DROP TABLE #dbccInput


You can use this to find out what's running now and get the SQL text for each job.



Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2010-09-14 : 05:11:03
it happens every time i run

this is the query



select telephone,dc,charge,datetimechargedsuccessfully,vendortxcode,'"'+vendortxcode as vendortxcode2 from transcations where datetimechargedsuccessfully>='20100201' and datetimechargedsuccessfully<='20100901' and chargedsuccessfully=1 and sitecode in(select sitecode from site where paymentprocessorid=2)

and vendortxcode not in(select replace(replace(vendortxcode,'"',''),'-','') as vendortxcode from c2010 where vendortxcode like '"c%' and transactiontype='"Payment"')


Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-09-14 : 05:57:23
Have you looked to see what other processes are running?

Try eliminating the IN parts inside the where clause


sitecode in (
select sitecode
from site where paymentprocessorid=2
)

Isn't this a static value? If so then either select it into a variable and then use that in the WHERE clause. Or just use the static value. (if that value doesn't change)



I think this might be your culprit

and vendortxcode not in (
select replace(replace(vendortxcode,'"',''),'-','') as vendortxcode
from c2010 where vendortxcode like '"c%' and transactiontype='"Payment"'
)

This looks pretty clunky.

If you run the query without this part in do you get results or does it still deadlock?


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-09-14 : 05:58:14
Also -- indexes on the tables? If there are no indexes / querys are unable to use indexes then queries take longer, hold more locks, generate more deadlocks.


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-09-14 : 05:58:27
And what's your isolation level?


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -