Showing posts with label single. Show all posts
Showing posts with label single. Show all posts

Wednesday, March 21, 2012

Deadlock on single table

We have one user who enters a transaction and then does a single row
update (updates all columns but only one is changing - this is due to
the way our sql is generated in the application), at this point
another user enter a transaction and tries to update the same row (he
understandably has to sit and wait while he is blocked by the original
user). The original user then updates the same row again at this
point the second user is chosen as a deadlock victim and killed. If I
try and recreate this with any other tables(or pubs) I get my expected
behaviour of the original user just doing 2 successful updates and the
second user then completing his update once the original user has
either committed his changes or rolled back. The query plan indicates
that a drop and insert of the row is happening (this is not the case
with any other tables where we get our expected behaviour). This only
happens when the index is clustered - if we use a non-clustered index
it does not occur.

Is this expected behaviour? it seems dangerous to me as the first
user has not commited or rolled back his updates. It was only
highlighted by a fault in our application that caused the second
update to be executed.

I have some thoughts about it being something to do with a row lock
being relased due to a delete / insest of the row in the second update
(we see this in the execution plan)....

Any help much appreciated as I am struggling to get my head round how
the second user was ever able to get hold of the resource.
CODA PBC wrote:

> We have one user who enters a transaction and then does a single row
> update (updates all columns but only one is changing - this is due to
> the way our sql is generated in the application), at this point
> another user enter a transaction and tries to update the same row (he
> understandably has to sit and wait while he is blocked by the original
> user). The original user then updates the same row again at this
> point the second user is chosen as a deadlock victim and killed. If I
> try and recreate this with any other tables(or pubs) I get my expected
> behaviour of the original user just doing 2 successful updates and the
> second user then completing his update once the original user has
> either committed his changes or rolled back. The query plan indicates
> that a drop and insert of the row is happening (this is not the case
> with any other tables where we get our expected behaviour). This only
> happens when the index is clustered - if we use a non-clustered index
> it does not occur.
> Is this expected behaviour? it seems dangerous to me as the first
> user has not commited or rolled back his updates. It was only
> highlighted by a fault in our application that caused the second
> update to be executed.
> I have some thoughts about it being something to do with a row lock
> being relased due to a delete / insest of the row in the second update
> (we see this in the execution plan)....
> Any help much appreciated as I am struggling to get my head round how
> the second user was ever able to get hold of the resource.

Hi. The trouble is that there is more than one lockable object
usually involved in an update. The datarow/page, and likely one
or more index page. It is unfortunate that with the clustered index,
your two users are obtaining those locks in different orders (a function
of the different query plans), causing a deadlock. I suppose that if both
updaters used the same plan (sending the exact same SQL), you would get
the behavior you want. It is sadly ugly that the generated code is
updating every column to change only one. Particularly if the change
includes the clustered key column(s), because it tells the DBMS that the
row has to be deleted from the clustered index (the last nodes of which
are the data pages), and re-inserted where the new key values dictate.
(It might be a fond hope that the DBMS could examine the key values
could be examined and the DBMS could interpret whether the row
actually has to move, but that is in reality not possible. The plan
needs to be made before the actual table data are accessed.).

I hope this helps,
Joe Weinstein at BEA

deadlock on a single table but multiple processes

Hi! We have a third party application that calls same stored procedure
simultaneously (around 10 spids). We are seeing hundreds of deadlocks.
Deadlock trace shows both spids are running exactly same statement within
the procedure. Depending upon input parameter the statement does either
insert or update. But the deadlock trace shows that deadlock happens when
both are running update statements. Multiple thread supposed to update same
table but different rows (at most couple of rows).
The object (key) they are deadlocking on is a non clustered index used to
search data for update. Update statement doesn't modify any column that
belongs to this non clustered index. Database is running on default
(read_commited) mode and Its sql 2000 SP4. I haven't seen "begin tran" in
the stored procedrue, so I assume that the statement is not a part of
explicit transaction.
Questions:
1. Why sql server is using update lock (And not the shared lock) on the non
clustered index which used to search the data. The update statement doesn't
modify this non clustered index. In below statement Index id 5 is on
position_id, security_alias and long_short_indicator.
2. Why deadlock and not just blocking? What is a fix for this?
Below is the update_statement that both SPID are running:
UPDATE CA
SET CANCEL_STATUS = 'Y',
UPDATE_SOURCE = @.in_update_source,
UPDATE_DATE = GETDATE()
from CASH.DBO.CASH_ACTIVITY CA (index(IND_CASH_ACT_SPD1))
WHERE POSITION_ID = @.nTargetPositionId
AND SECURITY_ALIAS = @.in_security_alias
AND LONG_SHORT_INDICATOR = 'L'
AND SOURCE_SECURITY_ALIAS = @.in_source_security_alias
AND SOURCE_LONG_SHORT_IND = @.in_source_long_short_ind
AND STAR_TAG25 = @.in_event_id
AND CASH_BAL_INST = @.in_event_sequence
AND CANCEL_FLAG = 'N'
AND REFLEXIVE_FLOW = 'Y'
Below is output of deadlock trace:
Deadlock encountered ... Printing deadlock information
2007-12-20 07:54:11.27 spid1
2007-12-20 07:54:11.27 spid1 Wait-for graph
2007-12-20 07:54:11.27 spid1
2007-12-20 07:54:11.27 spid1 Node:1
2007-12-20 07:54:11.27 spid1 KEY: 10:738101670:5 (5d01ef3a25c6)
CleanCnt:2 Mode: X Flags: 0x0
2007-12-20 07:54:11.27 spid1 Grant List 3::
2007-12-20 07:54:11.27 spid1 Owner:0x3dfb4480 Mode: X Flg:0x0
Ref:0 Life:02000000 SPID:589 ECID:0
2007-12-20 07:54:11.27 spid1 SPID: 589 ECID: 0 Statement Type: UPDATE
Line #: 42
2007-12-20 07:54:11.27 spid1 Input Buf: RPC Event:
PACE_MASTER..INSERT_CASH_ACTIVITY;1
2007-12-20 07:54:11.27 spid1 Requested By:
2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
SPID:470 ECID:0 Ec0x72B99520) Value:0xb61fa660 Cost0/7280)
2007-12-20 07:54:11.27 spid1
2007-12-20 07:54:11.27 spid1 Node:2
2007-12-20 07:54:11.27 spid1 KEY: 10:738101670:5 (d5013fde36a9)
CleanCnt:2 Mode: U Flags: 0x0
2007-12-20 07:54:11.27 spid1 Grant List 2::
2007-12-20 07:54:11.27 spid1 Owner:0xb69c32c0 Mode: U Flg:0x0
Ref:0 Life:00000001 SPID:470 ECID:0
2007-12-20 07:54:11.27 spid1 SPID: 470 ECID: 0 Statement Type: UPDATE
Line #: 42
2007-12-20 07:54:11.27 spid1 Input Buf: RPC Event:
PACE_MASTER..INSERT_CASH_ACTIVITY;1
2007-12-20 07:54:11.27 spid1 Requested By:
2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
SPID:589 ECID:0 Ec0x7445F520) Value:0x3dfb5460 Cost0/1FA4)
2007-12-20 07:54:11.27 spid1 Victim Resource Owner:
2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
SPID:589 ECID:0 Ec0x7445F520) Value:0x3dfb5460 Cost0/1FA4)
Hi,
May I know why Index hint is used in update statement
(index(IND_CASH_ACT_SPD1))?
Manu
"James" wrote:

> Hi! We have a third party application that calls same stored procedure
> simultaneously (around 10 spids). We are seeing hundreds of deadlocks.
> Deadlock trace shows both spids are running exactly same statement within
> the procedure. Depending upon input parameter the statement does either
> insert or update. But the deadlock trace shows that deadlock happens when
> both are running update statements. Multiple thread supposed to update same
> table but different rows (at most couple of rows).
> The object (key) they are deadlocking on is a non clustered index used to
> search data for update. Update statement doesn't modify any column that
> belongs to this non clustered index. Database is running on default
> (read_commited) mode and Its sql 2000 SP4. I haven't seen "begin tran" in
> the stored procedrue, so I assume that the statement is not a part of
> explicit transaction.
> Questions:
> 1. Why sql server is using update lock (And not the shared lock) on the non
> clustered index which used to search the data. The update statement doesn't
> modify this non clustered index. In below statement Index id 5 is on
> position_id, security_alias and long_short_indicator.
> 2. Why deadlock and not just blocking? What is a fix for this?
> Below is the update_statement that both SPID are running:
> UPDATE CA
> SET CANCEL_STATUS = 'Y',
> UPDATE_SOURCE = @.in_update_source,
> UPDATE_DATE = GETDATE()
> from CASH.DBO.CASH_ACTIVITY CA (index(IND_CASH_ACT_SPD1))
> WHERE POSITION_ID = @.nTargetPositionId
> AND SECURITY_ALIAS = @.in_security_alias
> AND LONG_SHORT_INDICATOR = 'L'
> AND SOURCE_SECURITY_ALIAS = @.in_source_security_alias
> AND SOURCE_LONG_SHORT_IND = @.in_source_long_short_ind
> AND STAR_TAG25 = @.in_event_id
> AND CASH_BAL_INST = @.in_event_sequence
> AND CANCEL_FLAG = 'N'
> AND REFLEXIVE_FLOW = 'Y'
> Below is output of deadlock trace:
> Deadlock encountered ... Printing deadlock information
> 2007-12-20 07:54:11.27 spid1
> 2007-12-20 07:54:11.27 spid1 Wait-for graph
> 2007-12-20 07:54:11.27 spid1
> 2007-12-20 07:54:11.27 spid1 Node:1
> 2007-12-20 07:54:11.27 spid1 KEY: 10:738101670:5 (5d01ef3a25c6)
> CleanCnt:2 Mode: X Flags: 0x0
> 2007-12-20 07:54:11.27 spid1 Grant List 3::
> 2007-12-20 07:54:11.27 spid1 Owner:0x3dfb4480 Mode: X Flg:0x0
> Ref:0 Life:02000000 SPID:589 ECID:0
> 2007-12-20 07:54:11.27 spid1 SPID: 589 ECID: 0 Statement Type: UPDATE
> Line #: 42
> 2007-12-20 07:54:11.27 spid1 Input Buf: RPC Event:
> PACE_MASTER..INSERT_CASH_ACTIVITY;1
> 2007-12-20 07:54:11.27 spid1 Requested By:
> 2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
> SPID:470 ECID:0 Ec0x72B99520) Value:0xb61fa660 Cost0/7280)
> 2007-12-20 07:54:11.27 spid1
> 2007-12-20 07:54:11.27 spid1 Node:2
> 2007-12-20 07:54:11.27 spid1 KEY: 10:738101670:5 (d5013fde36a9)
> CleanCnt:2 Mode: U Flags: 0x0
> 2007-12-20 07:54:11.27 spid1 Grant List 2::
> 2007-12-20 07:54:11.27 spid1 Owner:0xb69c32c0 Mode: U Flg:0x0
> Ref:0 Life:00000001 SPID:470 ECID:0
> 2007-12-20 07:54:11.27 spid1 SPID: 470 ECID: 0 Statement Type: UPDATE
> Line #: 42
> 2007-12-20 07:54:11.27 spid1 Input Buf: RPC Event:
> PACE_MASTER..INSERT_CASH_ACTIVITY;1
> 2007-12-20 07:54:11.27 spid1 Requested By:
> 2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
> SPID:589 ECID:0 Ec0x7445F520) Value:0x3dfb5460 Cost0/1FA4)
> 2007-12-20 07:54:11.27 spid1 Victim Resource Owner:
> 2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
> SPID:589 ECID:0 Ec0x7445F520) Value:0x3dfb5460 Cost0/1FA4)
>
>

deadlock on a single table but multiple processes

Hi! We have a third party application that calls same stored procedure
simultaneously (around 10 spids). We are seeing hundreds of deadlocks.
Deadlock trace shows both spids are running exactly same statement within
the procedure. Depending upon input parameter the statement does either
insert or update. But the deadlock trace shows that deadlock happens when
both are running update statements. Multiple thread supposed to update same
table but different rows (at most couple of rows).
The object (key) they are deadlocking on is a non clustered index used to
search data for update. Update statement doesn't modify any column that
belongs to this non clustered index. Database is running on default
(read_commited) mode and Its sql 2000 SP4. I haven't seen "begin tran" in
the stored procedrue, so I assume that the statement is not a part of
explicit transaction.
Questions:
1. Why sql server is using update lock (And not the shared lock) on the non
clustered index which used to search the data. The update statement doesn't
modify this non clustered index. In below statement Index id 5 is on
position_id, security_alias and long_short_indicator.
2. Why deadlock and not just blocking? What is a fix for this?
Below is the update_statement that both SPID are running:
UPDATE CA
SET CANCEL_STATUS = 'Y',
UPDATE_SOURCE = @.in_update_source,
UPDATE_DATE = GETDATE()
from CASH.DBO.CASH_ACTIVITY CA (index(IND_CASH_ACT_SPD1))
WHERE POSITION_ID = @.nTargetPositionId
AND SECURITY_ALIAS = @.in_security_alias
AND LONG_SHORT_INDICATOR = 'L'
AND SOURCE_SECURITY_ALIAS = @.in_source_security_alias
AND SOURCE_LONG_SHORT_IND = @.in_source_long_short_ind
AND STAR_TAG25 = @.in_event_id
AND CASH_BAL_INST = @.in_event_sequence
AND CANCEL_FLAG = 'N'
AND REFLEXIVE_FLOW = 'Y'
Below is output of deadlock trace:
Deadlock encountered ... Printing deadlock information
2007-12-20 07:54:11.27 spid1
2007-12-20 07:54:11.27 spid1 Wait-for graph
2007-12-20 07:54:11.27 spid1
2007-12-20 07:54:11.27 spid1 Node:1
2007-12-20 07:54:11.27 spid1 KEY: 10:738101670:5 (5d01ef3a25c6)
CleanCnt:2 Mode: X Flags: 0x0
2007-12-20 07:54:11.27 spid1 Grant List 3::
2007-12-20 07:54:11.27 spid1 Owner:0x3dfb4480 Mode: X Flg:0x0
Ref:0 Life:02000000 SPID:589 ECID:0
2007-12-20 07:54:11.27 spid1 SPID: 589 ECID: 0 Statement Type: UPDATE
Line #: 42
2007-12-20 07:54:11.27 spid1 Input Buf: RPC Event:
PACE_MASTER..INSERT_CASH_ACTIVITY;1
2007-12-20 07:54:11.27 spid1 Requested By:
2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
SPID:470 ECID:0 Ec0x72B99520) Value:0xb61fa660 Cost0/7280)
2007-12-20 07:54:11.27 spid1
2007-12-20 07:54:11.27 spid1 Node:2
2007-12-20 07:54:11.27 spid1 KEY: 10:738101670:5 (d5013fde36a9)
CleanCnt:2 Mode: U Flags: 0x0
2007-12-20 07:54:11.27 spid1 Grant List 2::
2007-12-20 07:54:11.27 spid1 Owner:0xb69c32c0 Mode: U Flg:0x0
Ref:0 Life:00000001 SPID:470 ECID:0
2007-12-20 07:54:11.27 spid1 SPID: 470 ECID: 0 Statement Type: UPDATE
Line #: 42
2007-12-20 07:54:11.27 spid1 Input Buf: RPC Event:
PACE_MASTER..INSERT_CASH_ACTIVITY;1
2007-12-20 07:54:11.27 spid1 Requested By:
2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
SPID:589 ECID:0 Ec0x7445F520) Value:0x3dfb5460 Cost0/1FA4)
2007-12-20 07:54:11.27 spid1 Victim Resource Owner:
2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
SPID:589 ECID:0 Ec0x7445F520) Value:0x3dfb5460 Cost0/1FA4)Hi,
May I know why Index hint is used in update statement
(index(IND_CASH_ACT_SPD1))?
Manu
"James" wrote:

> Hi! We have a third party application that calls same stored procedure
> simultaneously (around 10 spids). We are seeing hundreds of deadlocks.
> Deadlock trace shows both spids are running exactly same statement within
> the procedure. Depending upon input parameter the statement does either
> insert or update. But the deadlock trace shows that deadlock happens when
> both are running update statements. Multiple thread supposed to update sam
e
> table but different rows (at most couple of rows).
> The object (key) they are deadlocking on is a non clustered index used to
> search data for update. Update statement doesn't modify any column that
> belongs to this non clustered index. Database is running on default
> (read_commited) mode and Its sql 2000 SP4. I haven't seen "begin tran" in
> the stored procedrue, so I assume that the statement is not a part of
> explicit transaction.
> Questions:
> 1. Why sql server is using update lock (And not the shared lock) on the no
n
> clustered index which used to search the data. The update statement doesn'
t
> modify this non clustered index. In below statement Index id 5 is on
> position_id, security_alias and long_short_indicator.
> 2. Why deadlock and not just blocking? What is a fix for this?
> Below is the update_statement that both SPID are running:
> UPDATE CA
> SET CANCEL_STATUS = 'Y',
> UPDATE_SOURCE = @.in_update_source,
> UPDATE_DATE = GETDATE()
> from CASH.DBO.CASH_ACTIVITY CA (index(IND_CASH_ACT_SPD1))
> WHERE POSITION_ID = @.nTargetPositionId
> AND SECURITY_ALIAS = @.in_security_alias
> AND LONG_SHORT_INDICATOR = 'L'
> AND SOURCE_SECURITY_ALIAS = @.in_source_security_alias
> AND SOURCE_LONG_SHORT_IND = @.in_source_long_short_ind
> AND STAR_TAG25 = @.in_event_id
> AND CASH_BAL_INST = @.in_event_sequence
> AND CANCEL_FLAG = 'N'
> AND REFLEXIVE_FLOW = 'Y'
> Below is output of deadlock trace:
> Deadlock encountered ... Printing deadlock information
> 2007-12-20 07:54:11.27 spid1
> 2007-12-20 07:54:11.27 spid1 Wait-for graph
> 2007-12-20 07:54:11.27 spid1
> 2007-12-20 07:54:11.27 spid1 Node:1
> 2007-12-20 07:54:11.27 spid1 KEY: 10:738101670:5 (5d01ef3a25c6)
> CleanCnt:2 Mode: X Flags: 0x0
> 2007-12-20 07:54:11.27 spid1 Grant List 3::
> 2007-12-20 07:54:11.27 spid1 Owner:0x3dfb4480 Mode: X Flg:0x
0
> Ref:0 Life:02000000 SPID:589 ECID:0
> 2007-12-20 07:54:11.27 spid1 SPID: 589 ECID: 0 Statement Type: UPDA
TE
> Line #: 42
> 2007-12-20 07:54:11.27 spid1 Input Buf: RPC Event:
> PACE_MASTER..INSERT_CASH_ACTIVITY;1
> 2007-12-20 07:54:11.27 spid1 Requested By:
> 2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
> SPID:470 ECID:0 Ec0x72B99520) Value:0xb61fa660 Cost0/7280)
> 2007-12-20 07:54:11.27 spid1
> 2007-12-20 07:54:11.27 spid1 Node:2
> 2007-12-20 07:54:11.27 spid1 KEY: 10:738101670:5 (d5013fde36a9)
> CleanCnt:2 Mode: U Flags: 0x0
> 2007-12-20 07:54:11.27 spid1 Grant List 2::
> 2007-12-20 07:54:11.27 spid1 Owner:0xb69c32c0 Mode: U Flg:0x
0
> Ref:0 Life:00000001 SPID:470 ECID:0
> 2007-12-20 07:54:11.27 spid1 SPID: 470 ECID: 0 Statement Type: UPDA
TE
> Line #: 42
> 2007-12-20 07:54:11.27 spid1 Input Buf: RPC Event:
> PACE_MASTER..INSERT_CASH_ACTIVITY;1
> 2007-12-20 07:54:11.27 spid1 Requested By:
> 2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
> SPID:589 ECID:0 Ec0x7445F520) Value:0x3dfb5460 Cost0/1FA4)
> 2007-12-20 07:54:11.27 spid1 Victim Resource Owner:
> 2007-12-20 07:54:11.27 spid1 ResType:LockOwner Stype:'OR' Mode: U
> SPID:589 ECID:0 Ec0x7445F520) Value:0x3dfb5460 Cost0/1FA4)
>
>sql

deadlock on a single Select not in a transaction

Hi,
We have a web application developped in asp.net (I think it's not relevant,
but well, it's so you know)... Yesterday, we received the following message
"Transaction (Process ID 69) was deadlocked on lock resources with another
process and has been chosen as the deadlock victim. Rerun the transaction. "
The thing is, the query was a simple select with inner joins between 3
tables (like select fields from table1 inner join table2... inner join
table3...). This command is not in a transaction, so the deadlock seems
impossible. And moreover, the deadlock occurs on the DataReader.Read() not
on the Command.ExecuteReader(...).
Can someone explain why the deadlock can have occured and what could be the
cause and solution to it? Can it be a bug in SQL Server or in the .net
framework (I really doubt about it)?
thanks
ThunderMusic
What you're seeing is not concerning a Transaction as you are imagining it.
In essence, every operation performed by SQL Server is a transaction.
However, a Transaction (capital T) is a grouping of transactions (or
operations) into a single atomic unit which either fails or succeeds as a
whole. In this case, the reference is to to a (small t) transaction, which
is the operation of your query.
The exception occurs when 2 transactions (or processes) are trying to access
the same database object (such as a row in a table) at the same time. Each
process tries to get a lock on the object, and only one can. The other is
therefore killed. Here's a good article about this, and how to deal with it.
Notice that the most common tactic is simply to try again:
http://www.sql-server-performance.com/deadlocks.asp
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
"ThunderMusic" <NoSpAmdanlatathotmaildotcom@.NoSpAm.com> wrote in message
news:ewkig6PiHHA.2028@.TK2MSFTNGP03.phx.gbl...
> Hi,
> We have a web application developped in asp.net (I think it's not
> relevant, but well, it's so you know)... Yesterday, we received the
> following message "Transaction (Process ID 69) was deadlocked on lock
> resources with another process and has been chosen as the deadlock victim.
> Rerun the transaction. " The thing is, the query was a simple select with
> inner joins between 3 tables (like select fields from table1 inner join
> table2... inner join table3...). This command is not in a transaction, so
> the deadlock seems impossible. And moreover, the deadlock occurs on the
> DataReader.Read() not on the Command.ExecuteReader(...).
> Can someone explain why the deadlock can have occured and what could be
> the cause and solution to it? Can it be a bug in SQL Server or in the .net
> framework (I really doubt about it)?
> thanks
> ThunderMusic
>
|||You might enjoy reading the three articles starting at:
http://blogs.msdn.com/bartd/archive/2006/09/09/Deadlock-Troubleshooting_2C00_-Part-1.aspx
The bottom line is that a select is a single statement transaction that can
hold locks, and a conflicting desire for locks is what causes deadlocks.
(The Deadly Embrace, where each process is holding something the other
process wants.)
RLF
"ThunderMusic" <NoSpAmdanlatathotmaildotcom@.NoSpAm.com> wrote in message
news:ewkig6PiHHA.2028@.TK2MSFTNGP03.phx.gbl...
> Hi,
> We have a web application developped in asp.net (I think it's not
> relevant, but well, it's so you know)... Yesterday, we received the
> following message "Transaction (Process ID 69) was deadlocked on lock
> resources with another process and has been chosen as the deadlock victim.
> Rerun the transaction. " The thing is, the query was a simple select with
> inner joins between 3 tables (like select fields from table1 inner join
> table2... inner join table3...). This command is not in a transaction, so
> the deadlock seems impossible. And moreover, the deadlock occurs on the
> DataReader.Read() not on the Command.ExecuteReader(...).
> Can someone explain why the deadlock can have occured and what could be
> the cause and solution to it? Can it be a bug in SQL Server or in the .net
> framework (I really doubt about it)?
> thanks
> ThunderMusic
>
|||Kevin Spencer wrote:
...
> The exception occurs when 2 transactions (or processes) are trying to access
> the same database object (such as a row in a table) at the same time. Each
> process tries to get a lock on the object, and only one can. The other is
> therefore killed. Here's a good article about this, and how to deal with it.
> Notice that the most common tactic is simply to try again:
...
It's bit simplified, what you describe is not a deadlock situation. One
transaction will happily wait for lock to be released. Typical deadlock
situation is:
Transaction1 holds lock on A
Transcation2 holds lock on B
Transaction1 wants lock on B
Transcation2 wants lock on A
This cannot be resolved by waiting, so one transaction has to be killed.
Just a clarification.
Regards,
Goran

Monday, March 19, 2012

Deadlock in single session

Hi guys,
I need to stimulate a deadlock senerio in sql server.. i know i can do
it by openning two sessions of query analyzer.. is there any way of
creating a deadlock with a sigle session..
thanks to all in advance..This section of the SQL2005 BOL discusses, among other things, two tasks in
the same session causing a deadlock:
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/2ed3e3e7-5080-4fa3-b79a-585470602bc2.htm
But I have not tried to create such a deadlock myself.
Linchi
"ameen.abdullah@.gmail.com" wrote:
> Hi guys,
> I need to stimulate a deadlock senerio in sql server.. i know i can do
> it by openning two sessions of query analyzer.. is there any way of
> creating a deadlock with a sigle session..
> thanks to all in advance..
>|||Hi
Dan Guzman has written this example
-- session 1
CREATE TABLE MyTable
(
Col1 int NOT NULL
CONSTRAINT PK_MyTable PRIMARY KEY,
Col2 int NULL
)
INSERT INTO MyTable VALUES(1, NULL)
INSERT INTO MyTable VALUES(2, NULL)
GO
BEGIN TRAN
UPDATE MyTable SET Col2 = 1 WHERE Col1 = 1
GO
-- session 2
BEGIN TRAN
UPDATE MyTable SET Col2 = 2 WHERE Col1 = 2
GO
-- session 1
UPDATE MyTable SET Col2 = 3 WHERE Col1 = 2
GO
-- session 2
UPDATE MyTable SET Col2 = 4 WHERE Col1 = 1
GO
---
Connection 1: BEGIN TRAN
Connection 2: BEGIN TRAN
Connection 1: UPDATE id_Test 1
Connection 2: UPDATE id_Test 2
Connection 1: UPDATE id_Test 2 (waits for Connection 2 to COMMIT)
Connection 2: UPDATE id_Test 1 (waits for Connection 1 to COMMIT)
<ameen.abdullah@.gmail.com> wrote in message
news:1151513128.507479.134950@.y41g2000cwy.googlegroups.com...
> Hi guys,
> I need to stimulate a deadlock senerio in sql server.. i know i can do
> it by openning two sessions of query analyzer.. is there any way of
> creating a deadlock with a sigle session..
> thanks to all in advance..
>

Deadlock in single session

Hi guys,
I need to stimulate a deadlock senerio in sql server.. i know i can do
it by openning two sessions of query analyzer.. is there any way of
creating a deadlock with a sigle session..
thanks to all in advance..This section of the SQL2005 BOL discusses, among other things, two tasks in
the same session causing a deadlock:
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/2ed3e3e7-5080-4fa3-b79a-5854
70602bc2.htm
But I have not tried to create such a deadlock myself.
Linchi
"ameen.abdullah@.gmail.com" wrote:

> Hi guys,
> I need to stimulate a deadlock senerio in sql server.. i know i can do
> it by openning two sessions of query analyzer.. is there any way of
> creating a deadlock with a sigle session..
> thanks to all in advance..
>|||This section of the SQL2005 BOL discusses, among other things, two tasks in
the same session causing a deadlock:
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/2ed3e3e7-5080-4fa3-b79a-5854
70602bc2.htm
But I have not tried to create such a deadlock myself.
Linchi
"ameen.abdullah@.gmail.com" wrote:

> Hi guys,
> I need to stimulate a deadlock senerio in sql server.. i know i can do
> it by openning two sessions of query analyzer.. is there any way of
> creating a deadlock with a sigle session..
> thanks to all in advance..
>|||Hi
Dan Guzman has written this example
-- session 1
CREATE TABLE MyTable
(
Col1 int NOT NULL
CONSTRAINT PK_MyTable PRIMARY KEY,
Col2 int NULL
)
INSERT INTO MyTable VALUES(1, NULL)
INSERT INTO MyTable VALUES(2, NULL)
GO
BEGIN TRAN
UPDATE MyTable SET Col2 = 1 WHERE Col1 = 1
GO
-- session 2
BEGIN TRAN
UPDATE MyTable SET Col2 = 2 WHERE Col1 = 2
GO
-- session 1
UPDATE MyTable SET Col2 = 3 WHERE Col1 = 2
GO
-- session 2
UPDATE MyTable SET Col2 = 4 WHERE Col1 = 1
GO
---
Connection 1: BEGIN TRAN
Connection 2: BEGIN TRAN
Connection 1: UPDATE id_Test 1
Connection 2: UPDATE id_Test 2
Connection 1: UPDATE id_Test 2 (waits for Connection 2 to COMMIT)
Connection 2: UPDATE id_Test 1 (waits for Connection 1 to COMMIT)
<ameen.abdullah@.gmail.com> wrote in message
news:1151513128.507479.134950@.y41g2000cwy.googlegroups.com...
> Hi guys,
> I need to stimulate a deadlock senerio in sql server.. i know i can do
> it by openning two sessions of query analyzer.. is there any way of
> creating a deadlock with a sigle session..
> thanks to all in advance..
>|||Hi
Dan Guzman has written this example
-- session 1
CREATE TABLE MyTable
(
Col1 int NOT NULL
CONSTRAINT PK_MyTable PRIMARY KEY,
Col2 int NULL
)
INSERT INTO MyTable VALUES(1, NULL)
INSERT INTO MyTable VALUES(2, NULL)
GO
BEGIN TRAN
UPDATE MyTable SET Col2 = 1 WHERE Col1 = 1
GO
-- session 2
BEGIN TRAN
UPDATE MyTable SET Col2 = 2 WHERE Col1 = 2
GO
-- session 1
UPDATE MyTable SET Col2 = 3 WHERE Col1 = 2
GO
-- session 2
UPDATE MyTable SET Col2 = 4 WHERE Col1 = 1
GO
---
Connection 1: BEGIN TRAN
Connection 2: BEGIN TRAN
Connection 1: UPDATE id_Test 1
Connection 2: UPDATE id_Test 2
Connection 1: UPDATE id_Test 2 (waits for Connection 2 to COMMIT)
Connection 2: UPDATE id_Test 1 (waits for Connection 1 to COMMIT)
<ameen.abdullah@.gmail.com> wrote in message
news:1151513128.507479.134950@.y41g2000cwy.googlegroups.com...
> Hi guys,
> I need to stimulate a deadlock senerio in sql server.. i know i can do
> it by openning two sessions of query analyzer.. is there any way of
> creating a deadlock with a sigle session..
> thanks to all in advance..
>

deadlock in agent job

I have a job with a single t-sql step. The tsql executes a stored proc that
occasionally deadlocks.
I know i can't trap the deadlock in the stored proc, but I'd like to trap
the deadlock in the agent job, and retry the stored proc.
What is the best way to handle this?
-Rand yThis is normal behavior. A trigger is executed for each statement that cause
s
the trigger to fire and not for each row affected by the statement. See
"Multirow Considerations" in BOL.
AMB
"Randy" wrote:

> I have a job with a single t-sql step. The tsql executes a stored proc th
at
> occasionally deadlocks.
> I know i can't trap the deadlock in the stored proc, but I'd like to trap
> the deadlock in the agent job, and retry the stored proc.
> What is the best way to handle this?
> -Rand y
>
>|||Sorry, wrong place.
AMB
"Alejandro Mesa" wrote:
> This is normal behavior. A trigger is executed for each statement that cau
ses
> the trigger to fire and not for each row affected by the statement. See
> "Multirow Considerations" in BOL.
>
> AMB
> "Randy" wrote:
>|||What about increasing "Retry attempts" in the advanced tab when creating or
modifing the job step.
AMB
"Randy" wrote:

> I have a job with a single t-sql step. The tsql executes a stored proc th
at
> occasionally deadlocks.
> I know i can't trap the deadlock in the stored proc, but I'd like to trap
> the deadlock in the agent job, and retry the stored proc.
> What is the best way to handle this?
> -Rand y
>
>

Deadlock help on single table

I am experiencing a large volume of deadlocks with a stored procedure I have
written. The stored procedure only ever accesses one table. First it
performs a couple of selects to check if a record exists or not and if it
doesn't then it tries to insert it.
Its on the insert that I get the deadlock. Out of 23 concurrent processes,
20 of them get deadlocked.
Each stored procedure runs under the serializable isolation setting (they
have to due to the system that invokes them).
I didn't realise that you could get deadlocks on the same table - I thought
it could only occur between tables.
There are a few indexes on the table which I think could be the cause for
the deadlocks.
Any tips on how to reduce deadlocking in such a scenario?
I was thinking that I could "lock" the record that I want to create first
before actually inserting it, then perform the selects and then the insert.
But I don't know how I can "lock" a record that does not exist.
Thanks.
McGy
[url]http://mcgy.blogspot.com[/url]Could you please post the procedure definition?
ML
http://milambda.blogspot.com/|||>>>>>>> This is the table:
CREATE TABLE [dbo].[DNX_CIPFile] (
[Filename] [char] (32) NOT NULL ,
[Id] [int] IDENTITY (1, 1) NOT NULL ,
[SequenceNumber] [int] NOT NULL ,
[LoadStartTime] [datetime] NOT NULL ,
[Type] [char] (32) NOT NULL ,
[LoadEndTime] [datetime] NULL ,
[Records] [int] NOT NULL ,
[Inserts] [int] NOT NULL ,
[Updates] [int] NOT NULL ,
[Batches] [int] NOT NULL
)

CREATE UNIQUE INDEX UX_DNX_CIPFile_1 ON [dbo].[DNX_CIPFile] ([Filename])
CREATE UNIQUE INDEX UX_DNX_CIPFile_2 ON [dbo].[DNX_CIPFile] ([Type],
[SequenceNumber] desc)
ALTER TABLE [dbo].[DNX_CIPFile] ADD
CONSTRAINT [PK_DNX_CIPFile] PRIMARY KEY NONCLUSTERED
(
[Id]
) WITH FILLFACTOR = 90 ON [PRIMARY]
create procedure DNX_LoadDailyCIPFiles_CommenceLoad
@.FileName char ( 32 ),
@.Sequence int,
@.Type char ( 32 )
as
-- see if a record already exists.
if exists (select [Id] from DNX_CIPFile where [Filename] = @.FileName)
begin
RETURN
end
declare @.SequenceNumber int
select @.SequenceNumber = max(SequenceNumber) from DNX_CIPFile where [Type] =
@.Type
-- ensure if file type not exist
if @.SequenceNumber is NULL set @.SequenceNumber = 0
--ensure that it is next sequence number
if @.SequenceNumber + 1 <> @.Sequence
begin
RETURN
end
-- file does not exist and is the next in the sequence
insert into
DNX_CIPFile
(
[Filename] ,
[SequenceNumber] ,
[LoadStartTime] ,
[Type] ,
[LoadEndTime] ,
[Records] ,
[Inserts] ,
[Updates] ,
[Batches]
)
values
(
@.FileName,
@.Sequence,
getdate ( ),
@.Type,
null,
0,
0,
0,
0
)
McGy
[url]http://mcgy.blogspot.com[/url]
"ML" <ML@.discussions.microsoft.com> wrote in message
news:A2FC6E36-C013-441D-ACD3-758C917AEA67@.microsoft.com...
> Could you please post the procedure definition?
>
> ML
> --
> http://milambda.blogspot.com/|||Try adding the WITH(UPDLOCK) table hint when reading from the table - this
will enable other processes to access the same row(s) without causing a
deadlock.
I.e.:
select @.SequenceNumber = max(SequenceNumber)
from DNX_CIPFile with(updlock, rangelock, holdlock)
where ([Type] = @.Type)
rangelock - locks the entire range of rows corresponding to the criteria;
holdlock - keeps "intruders" out for the duration of the process (also try
without it).
And most importantly: test, re-test, double-test and then test again.
ML
http://milambda.blogspot.com/|||Cheers mate. I will try that out.
McGy
[url]http://mcgy.blogspot.com[/url]
"ML" <ML@.discussions.microsoft.com> wrote in message
news:829AAF22-D55D-4575-9FD2-014FAA1015D8@.microsoft.com...
> Try adding the WITH(UPDLOCK) table hint when reading from the table - this
> will enable other processes to access the same row(s) without causing a
> deadlock.
> I.e.:
> select @.SequenceNumber = max(SequenceNumber)
> from DNX_CIPFile with(updlock, rangelock, holdlock)
> where ([Type] = @.Type)
> rangelock - locks the entire range of rows corresponding to the criteria;
> holdlock - keeps "intruders" out for the duration of the process (also try
> without it).
> And most importantly: test, re-test, double-test and then test again.
>
> ML
> --
> http://milambda.blogspot.com/|||Check out Alejandro's suggestion - it looks even better.
Also think again about the reasons behind the need for serializable
isolation level - I think the default (read committed) isolation level would
suffice.
ML
http://milambda.blogspot.com/|||Try,
-- file does not exist and is the next in the sequence
insert into
DNX_CIPFile
(
[Filename] ,
[SequenceNumber] ,
[LoadStartTime] ,
[Type] ,
[LoadEndTime] ,
[Records] ,
[Inserts] ,
[Updates] ,
[Batches]
)
select
@.FileName,
@.Sequence,
getdate ( ),
@.Type,
null,
0,
0,
0,
0
where
not exists(select [Id] from DNX_CIPFile where [Filename] = @.FileName)
and
(select isnull(max(SequenceNumber), 0) + 1 from DNX_CIPFile where [Type]
= @.Type) = @.Sequence
go
AMB
"McGy" wrote:

> CREATE TABLE [dbo].[DNX_CIPFile] (
> [Filename] [char] (32) NOT NULL ,
> [Id] [int] IDENTITY (1, 1) NOT NULL ,
> [SequenceNumber] [int] NOT NULL ,
> [LoadStartTime] [datetime] NOT NULL ,
> [Type] [char] (32) NOT NULL ,
> [LoadEndTime] [datetime] NULL ,
> [Records] [int] NOT NULL ,
> [Inserts] [int] NOT NULL ,
> [Updates] [int] NOT NULL ,
> [Batches] [int] NOT NULL
> )
>
> CREATE UNIQUE INDEX UX_DNX_CIPFile_1 ON [dbo].[DNX_CIPFile] ([Filename])
> CREATE UNIQUE INDEX UX_DNX_CIPFile_2 ON [dbo].[DNX_CIPFile] ([Type],
> [SequenceNumber] desc)
> ALTER TABLE [dbo].[DNX_CIPFile] ADD
> CONSTRAINT [PK_DNX_CIPFile] PRIMARY KEY NONCLUSTERED
> (
> [Id]
> ) WITH FILLFACTOR = 90 ON [PRIMARY]
>
> create procedure DNX_LoadDailyCIPFiles_CommenceLoad
> @.FileName char ( 32 ),
> @.Sequence int,
> @.Type char ( 32 )
> as
> -- see if a record already exists.
> if exists (select [Id] from DNX_CIPFile where [Filename] = @.FileName)
> begin
> RETURN
> end
> declare @.SequenceNumber int
> select @.SequenceNumber = max(SequenceNumber) from DNX_CIPFile where [Type] =
> @.Type
> -- ensure if file type not exist
> if @.SequenceNumber is NULL set @.SequenceNumber = 0
> --ensure that it is next sequence number
> if @.SequenceNumber + 1 <> @.Sequence
> begin
> RETURN
> end
> -- file does not exist and is the next in the sequence
> insert into
> DNX_CIPFile
> (
> [Filename] ,
> [SequenceNumber] ,
> [LoadStartTime] ,
> [Type] ,
> [LoadEndTime] ,
> [Records] ,
> [Inserts] ,
> [Updates] ,
> [Batches]
> )
> values
> (
> @.FileName,
> @.Sequence,
> getdate ( ),
> @.Type,
> null,
> 0,
> 0,
> 0,
> 0
> )
>
> --
> McGy
> [url]http://mcgy.blogspot.com[/url]
>
> "ML" <ML@.discussions.microsoft.com> wrote in message
> news:A2FC6E36-C013-441D-ACD3-758C917AEA67@.microsoft.com...
>
>|||Three steps make one giant leap? :)
Nice one.
ML
http://milambda.blogspot.com/|||Hi. Thanks for the suggestions and the rewritten query below. Unfortunately
I cannot rewrite as suggested below because I need to check specifically for
the existence of the record and the max sequence number because I return
values to the calling program (I removed that bit of script from the SQL).
However, I have since tried using the with (updlock) on the first sql
statement and it improved the situation no end. No more deadlocks!! I ran
some load tests to check for problems and all seemed to go through fine.
I have to use serializable as the calling program (BizTalk Server) specifies
as such and it can't be changed.
Thanks again.
McGy
[url]http://mcgy.blogspot.com[/url]
"Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in message
news:232C19F5-FB40-4DC1-A0B7-0D3F1C065757@.microsoft.com...
> Try,
> -- file does not exist and is the next in the sequence
> insert into
> DNX_CIPFile
> (
> [Filename] ,
> [SequenceNumber] ,
> [LoadStartTime] ,
> [Type] ,
> [LoadEndTime] ,
> [Records] ,
> [Inserts] ,
> [Updates] ,
> [Batches]
> )
> select
> @.FileName,
> @.Sequence,
> getdate ( ),
> @.Type,
> null,
> 0,
> 0,
> 0,
> 0
> where
> not exists(select [Id] from DNX_CIPFile where [Filename] = @.FileName)
> and
> (select isnull(max(SequenceNumber), 0) + 1 from DNX_CIPFile where
[Type]
> = @.Type) = @.Sequence
> go
>
> AMB
> "McGy" wrote:
>
[Type] =|||Just remember this newsgroup . :)
ML
http://milambda.blogspot.com/

deadlock due to transactions within a single SPID(syslockinfo table)

I got a deadlock scenario and so I took a snap shot of the syslockinfo table. I found out an interesting scenario where the deadlock is because of two transactions within the same spid.

rsc_text rsc_bin rsc_valblk rsc_dbid rsc_indid rsc_objid rsc_type rsc_flag req_mode req_status req_refcnt req_cryrefcnt req_lifetime req_spid req_ecid req_ownertype req_transactionID req_transactionUOW

1:31840 0x00060200607C00000100000000000000 0x00000000000000000000000000000000 2 0 0 6 0 5 1 1 0 0 113 0 1 96462284 00000000-0000-0000-0000-000000000000

1:31840 0x00060200607C00000100000000000000 0x00000000000000000000000000000000 2 0 0 6 0 5 3 1 0 67108864 113 0 1 96594607 00000000-0000-0000-0000-000000000000

For the first one the lock was granted(transactionID:96462284)
but for the next one(transactionId:96594607) it was put in wait state and SQL server detected it as a deadlock.

I just wanted some clarifications.
1) what is the significance of req_transactionID column in syslockinfo table?
2) what is the relationship between req_transactionId column and spid column?
3) In case of nested transactions what will be the values of these 2 columns and what will be the relationship between them in that scenario?
4) In this case the deadlock is occurring while executing a SP(the nested level of calls go till 3rd level).
5) Will there be contention for locks between transactions within a single spid.

it is something like this:
sp_cache
sp_cache1
while
sp_cache2
end while

the deadlock occurred when executing sp_cache 2.
At that time there were only two transactionId values in the syslockinfo table for this spid,They were:
1) 96462284
2)96594607

If some body could please help me it would be really helpful for me.

Thanks in advance!!

have you got a deadlock trace set on your server, or a deadlock graph from profiler (if on 2005)?

either would give alot more diagnostic info

|||

Hi, Yes this the exact situation i am facing here as well.

Point to note here is the database is TEMPDB. (i.e. rsc_dbid = 2).

To see the below text properly, please copy from here and paste in notepad then it would be easier to understand.

rsc_text rsc_bin rsc_valblk rsc_dbid rsc_indid rsc_objid rsc_type rsc_flag req_mode req_status req_refcnt req_cryrefcnt req_lifetime req_spid req_ecid req_ownertype req_transactionID req_transactionUOW
1:25339 0x00088243378C00000100000000000000 0x00000000000000000000000000000000 2 0 0 6 0 5 1 1 0 0 149 0 1 87573395 00000000-0000-0000-0000-000000000000
1:25339 0x00088243378C00000100000000000000 0x00000000000000000000000000000000 2 0 0 6 0 5 3 1 0 58219975 149 0 1 87685718 00000000-0000-0000-0000-000000000000

As suggested by rb1n I have enabled the traces and the profiler logs as well but nothing much helpful exists there.

Basically it really requires understanding about the field "req_transactionID " in syslockinfo table. Not much information is available about this filed on Microsoft websites.

Is it right to say:

- In a normal situation one SPID will have same "req_transactionID " in syslockinfo table?

Reason for asking this is: On normal days when my SP executes (lest say under SPID X) without any problem the syslockinfo table has same "req_transactionID " for all transaction under SPID X . i.e. "req_transactionID " never changes. Days, when deadlock happens the "req_transactionID " is different and have same kind of situation as posted above.

- If not agree with the above understanding then can someone tell me in what situation the "req_transactionID " can be different for same SPID? Or simply what is the significance of column "req_transactionID ”?

- Is this something Microsoft is aware of?

Thanks very much for you time on this.
|||did you get a deadlock graph logged in sql profiler? (in the TextData)|||The deadlock occurred in sql server 2000.

I have attached the error log below:

Wait-for graph

LockBig Smileeadlock Chain Deadlock Chain SPID = 112
Node:1
PAG: 2:4:103776 CleanCnt:2 Mode: X Flags: 0x0
Grant List 1::
Owner:0x4b713220 Mode: X Flg:0x0 Ref:1 Life:00000000 SPID:112 ECID:0
SPID: 112 ECID: 0 Statement Type: CREATE INDEX Line #: 1
Input Buf: RPC Event: gsa_proc_homepage_cache_refresh;1
Requested By:
ResType:LockOwner Stype:'OR' Mode: X SPID:112 ECID:0 EcSad0x33705528) Value:0x47908120 CostSad51/B87FB18)

deadlock due to transactions within a single SPID(syslockinfo table)

I got a deadlock scenario and so I took a snap shot of the syslockinfo table. I found out an interesting scenario where the deadlock is because of two transactions within the same spid.

rsc_text rsc_bin rsc_valblk rsc_dbid rsc_indid rsc_objid rsc_type rsc_flag req_mode req_status req_refcnt req_cryrefcnt req_lifetime req_spid req_ecid req_ownertype req_transactionID req_transactionUOW

1:31840 0x00060200607C00000100000000000000 0x00000000000000000000000000000000 2 0 0 6 0 5 1 1 0 0 113 0 1 96462284 00000000-0000-0000-0000-000000000000

1:31840 0x00060200607C00000100000000000000 0x00000000000000000000000000000000 2 0 0 6 0 5 3 1 0 67108864 113 0 1 96594607 00000000-0000-0000-0000-000000000000

For the first one the lock was granted(transactionID:96462284)
but for the next one(transactionId:96594607) it was put in wait state and SQL server detected it as a deadlock.

I just wanted some clarifications.
1) what is the significance of req_transactionID column in syslockinfo table?
2) what is the relationship between req_transactionId column and spid column?
3) In case of nested transactions what will be the values of these 2 columns and what will be the relationship between them in that scenario?
4) In this case the deadlock is occurring while executing a SP(the nested level of calls go till 3rd level).
5) Will there be contention for locks between transactions within a single spid.

it is something like this:
sp_cache
sp_cache1
while
sp_cache2
end while

the deadlock occurred when executing sp_cache 2.
At that time there were only two transactionId values in the syslockinfo table for this spid,They were:
1) 96462284
2)96594607

If some body could please help me it would be really helpful for me.

Thanks in advance!!

have you got a deadlock trace set on your server, or a deadlock graph from profiler (if on 2005)?

either would give alot more diagnostic info

|||

Hi, Yes this the exact situation i am facing here as well.

Point to note here is the database is TEMPDB. (i.e. rsc_dbid = 2).

To see the below text properly, please copy from here and paste in notepad then it would be easier to understand.

rsc_text rsc_bin rsc_valblk rsc_dbid rsc_indid rsc_objid rsc_type rsc_flag req_mode req_status req_refcnt req_cryrefcnt req_lifetime req_spid req_ecid req_ownertype req_transactionID req_transactionUOW
1:25339 0x00088243378C00000100000000000000 0x00000000000000000000000000000000 2 0 0 6 0 5 1 1 0 0 149 0 1 87573395 00000000-0000-0000-0000-000000000000
1:25339 0x00088243378C00000100000000000000 0x00000000000000000000000000000000 2 0 0 6 0 5 3 1 0 58219975 149 0 1 87685718 00000000-0000-0000-0000-000000000000

As suggested by rb1n I have enabled the traces and the profiler logs as well but nothing much helpful exists there.

Basically it really requires understanding about the field "req_transactionID " in syslockinfo table. Not much information is available about this filed on Microsoft websites.

Is it right to say:

- In a normal situation one SPID will have same "req_transactionID " in syslockinfo table?

Reason for asking this is: On normal days when my SP executes (lest say under SPID X) without any problem the syslockinfo table has same "req_transactionID " for all transaction under SPID X . i.e. "req_transactionID " never changes. Days, when deadlock happens the "req_transactionID " is different and have same kind of situation as posted above.

- If not agree with the above understanding then can someone tell me in what situation the "req_transactionID " can be different for same SPID? Or simply what is the significance of column "req_transactionID ”?

- Is this something Microsoft is aware of?

Thanks very much for you time on this.
|||did you get a deadlock graph logged in sql profiler? (in the TextData)|||The deadlock occurred in sql server 2000.

I have attached the error log below:

Wait-for graph

LockBig Smileeadlock Chain Deadlock Chain SPID = 112
Node:1
PAG: 2:4:103776 CleanCnt:2 Mode: X Flags: 0x0
Grant List 1::
Owner:0x4b713220 Mode: X Flg:0x0 Ref:1 Life:00000000 SPID:112 ECID:0
SPID: 112 ECID: 0 Statement Type: CREATE INDEX Line #: 1
Input Buf: RPC Event: gsa_proc_homepage_cache_refresh;1
Requested By:
ResType:LockOwner Stype:'OR' Mode: X SPID:112 ECID:0 EcSad0x33705528) Value:0x47908120 CostSad51/B87FB18)

Sunday, March 11, 2012

Deadlock accessing variables

I am trying to access a single variable in a script and a deadlock error continues to come up. I have a single string variable that is added to the readwritevariables collection in the editor. I am trying to execute the following code:

Dim variables As Variables

Try

Dts.VariableDispenser.LockForWrite("Test")

Dts.VariableDispenser.GetVariables(variables)

Catch ex As Exception

Throw ex

Finally

variables.Unlock()

End Try

I have installed Service Pack2 and this error continues. I know it has been posted on before and I appreciate any help.

Thanks

You shouldn't need to lock the variable in your script if you've added it in the editor. Try either removing the lock in your script or removing the variable in the editor.|||

Thank you. It took me awhile but I figured it out. If I was smart enough to read the error I would have figured it out sooner.

Thanks again