Hi all,
In my development environment, I seek to recreate a production issue we face with MSSQL 2005. This issue has two parts:
The Problem
1) A deadlock occurs and MSSQL selects one connection ("Connection X") as the 'victim'. 2) All subsequent attempts to use "Connection X" fail (we use connection pooling). MSSQL says "The server failed to resume the transaction"
Of the two, #2 if more serious: since "connection X" is whacked every "round robin" attempt to re-use "connection x" fails--and mysterious "random" errors appear to the user. We must restart the server.
Why I Write
At this point, however, I wish to recreate problem #1. I can create a deadlock easily.
But here's my issue: whereas in production, MSSQL chooses one connection (SPID) as the 'deadlock victim', in my test environment, the deadlock just hangs...and hangs and hangs. Forever? I'm not sure, but I left it hanging overnight and it still hung in the morning.
So here's the question: how can I make sql server "choose a deadlock victim" when a deadlock occurs?
Attempts so Far
I tried setting the "lock_timeout" parameter via the jdbc url ("lockTimeout=5000"), however I got a different message than in production (in test,"Lock request time out period exceeded." instead of in production "Transaction (Process ID 59) was deadlocked on lock resources with another process and has been chosen as the deadlock victim.")
Some details on problem #2
I've researched this "unable to resume the transaction" problem and found a few things:
- bad exception handling may cause this problem. E.g.: the java code does not close the Statement/PreparedStatement and the driver's implementation of "Connection" is stuck with a bad/stale/old "transaction ID"
- A jdbc driver upgrade may make the problem go away.
For now, however, I just want to recreate a deadlock and make sql server "choose a deadlock victim".
thanks in advance!
Appendix A. Technical Environment
Development:
- sql server 2005 SP3 (9.00.4035.00)
- driver: sqljdbc.jar version 1.0
- Jboss 3.2.6
- jdbc url: jdbc:sqlserver://<>;
Production:
- sql server 2005 SP2 (9.00.3042.00)
- driver: sqljdbc.jar version 1.0
- Jboss 3.2.6
- jdbc url: jdbc:sqlserver://<>;
Appendix B. Steps to force a deadlock
- get connection A
- get connection B
- run sql1 with connection A
- run sql2 with connection B
- run sql1 with connection B
- run sql2 with connection A
where sql1: update member set name = name + 'x' WHERE member_id = 71
sql2: update member set name = name + 'x' WHERE member_id = 72