views:

21

answers:

2

In our applications we don't use either ADO.NET transaction or SQL Server transactions in procedures and now we are getting the below error in our website when multiple people are using.

Transaction (Process ID 73) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction

Is this error due to the lack of transactions? I thought the consistency will be handled by the DB itself.

And one thing I noticed that SQLCommand.Timeout property has set to 10000. Will this be an issue for the error?

I am trying to solve this issue ASAP. Please help.

EDIT

I saw the Isolationlevel property of ADO.NET transaction, so if I use ADO.NET transaction with proper isolationlevel property like "ReadUncommitted" during reading and "Serializable" during writing?

A: 

IsolationLevel is your best bet. Default serialization level of transactions is "Serializable" which is the most stringent and if at this level there is a circular reference chances of deadlock are very high. Set it to ReadCommitted while reading and let it be Serializable while writing.

Sql server can use implicit transactions which is what might be happening in your case. Try setting it off:

SET IMPLICIT_TRANSACTIONS OFF;

Read about it here: http://msdn.microsoft.com/en-us/library/ms190230.aspx

Sidharth Panwar
any comment on timeout property value of 10000?
Antoops
Don't think timeout is a problem.
Sidharth Panwar
+2  A: 

Every SQL DML (INSERT, UPDATE, DELETE) or DQL (SELECT) statement runs inside a transaction. The default behaviour for SQL Server is for it to open a new transaction (if one doesn't exist), and if the statement completes without errors, to automatically commit the transaction.

The IMPLICIT_TRANSACTIONS behaviour that Sidharth mentions basically gets SQL Server to change it's behaviour somewhat - it leaves the transaction open when the statement completes.

To get better information in the SQL Server error log, you can turn on a trace flag. This will then tell you which connections were involved in the deadlock (not just the one that got killed), and which resources were involved. You may then be able to determine what pattern of behaviour is leading to the deadlocks.

If you're unable to determine the underlying cause, you may have to add some additional code to your application - that catches sql errors due to deadlocks, and retries the command multiple times. This is usually the last resort - it's better to determine which tables/indexes are involved, and work out a strategy that avoids the deadlocks in the first place.

Damien_The_Unbeliever
I turned on deadlock info by DBCC TRACEON (1204). Now waiting for next deadlock to analyze more.
Antoops

related questions