473,386 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

deadlocks in sql server

Hi
I'm having a problem with deadlocks in a table in SQL server when
trying to update it through Biztalk 2004. There is no problem when I
use the same Biztalk solution to update a similar dummy table, but
when I try updating the original table in the production database,
some transactions are updated successfully whereas others become the
victim of the deadlock (Transaction (Process ID 185) was deadlocked on
lock resources with another process and has been chosen as the
deadlock victim. Rerun the transaction). The table that is updated is
also being used by another application that just selects rows from it.

As a workaround, I have used recursion in the code that updates the
table. The function is put through a recursive loop whenever the
deadlock exception(#1205) is caught. It keeps on trying to update the
table until the updation is successful or another exception (not the
deadlock one) is caught. i.e.
Bool Update_IVR(string amount, string customer_id)
{
Try
{
//updation code
}
}
Catch (exception ex)
{
If( ex.message == deadlock message)
{
Bool succ =Update_IVR (amount, customer_id) //recursion
Return succ;
}
Else //error handling code
}

After introducing this code, the problem did not occur for the next
13000 transactions. Then I got the error again four times along with a
timeout error (Timeout expired. The timeout period elapsed prior to
completion of the operation or the server is not responding). However
for the next 17000 transactions (to date) this error has not showed
up.

Thanks

Hasan
Jul 20 '05 #1
3 8283
Hasan (ha***@mobilink.net) writes:
I'm having a problem with deadlocks in a table in SQL server when
trying to update it through Biztalk 2004. There is no problem when I
use the same Biztalk solution to update a similar dummy table, but
when I try updating the original table in the production database,
some transactions are updated successfully whereas others become the
victim of the deadlock (Transaction (Process ID 185) was deadlocked on
lock resources with another process and has been chosen as the
deadlock victim. Rerun the transaction). The table that is updated is
also being used by another application that just selects rows from it.

As a workaround, I have used recursion in the code that updates the
table. The function is put through a recursive loop whenever the
deadlock exception(#1205) is caught. It keeps on trying to update the
table until the updation is successful or another exception (not the
deadlock one) is caught. i.e.
...
After introducing this code, the problem did not occur for the next
13000 transactions. Then I got the error again four times along with a
timeout error (Timeout expired. The timeout period elapsed prior to
completion of the operation or the server is not responding). However
for the next 17000 transactions (to date) this error has not showed
up.


It seems that you have locking problems in your application, and you
need to perform further analysis to find out where the problem might lie.

Deadlock happens when two processes is trying to access resources already
locked by the other. Here is a simple example:

BEGIN TRANSACTION BEGIN TRANSACTION
UPDATE tbla UPDATE tblb
SET col = 12 SET col = 98
WHERE keycol = 1 WHERE keycol = 8

UPDATE tblb UPDATE tbla
SET col = 88 SET col = 546
WHERE keycol = 8 WHERE keycol = 1
COMMIT TRANSACTION COMMIT TRANSACTION

This will deadlock, when the two processes come to their second UPDATE
statement, they will wait for each other. SQL Server detects this
situation and select one as a deadlock victim.

"Timeout expired" on the other hand can have many causes. This is a timeout
which is set up by the client library, and of which SQL Server has no
knowledge. A timeout could elapse because of long processing time, but
also because the process is blocked by another process. Important to
know is that when you get an timeout expired, you should probably submit
a "IF @@trancount > 0 ROLLBACK TRANSACTION", because there is no automatic
rollback in this case.

I would assume that in your case the Timeout Expired was due to blocking.

In order to understand the cause of deadlocks, you need to get more
information. One way is to set up a Profiler trace to catch deadlocks.
You can also enable trace flags 1204 and 3605 by adding -T1204 and -T3605
to the startup parameters in Enterprise Manger, and restart SQL Server.
In this case, each deadlock will be logged in the SQL Server error log.
In fairly cryptic manner, but neverless.

To detect blocking and what the involved processes are doing, I have a
stored procedure, which is good for this. It's called aba_lockinfo and
you find it on http://www.sommarskog.se/sqlutil/aba_lockinfo.html.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #2


Thanks for your reply. I have a better understadning of whats going on
now. Can you please explain to me how to set the trace flags you've
mentioned.

Thanks
Hasan

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3
Hasan Sheikh (ha***@mobilink.net) writes:
Thanks for your reply. I have a better understadning of whats going on
now. Can you please explain to me how to set the trace flags you've
mentioned.


As I said:

You can also enable trace flags 1204 and 3605 by adding -T1204 and -T3605
to the startup parameters in Enterprise Manger, and restart SQL Server

To get there, right-click the server in EM, select Properties. Startup
Parameters is a button at the buttom of the General tab.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: AKS | last post by:
I am getting lot of deadlocks in my application. As it is very complex ti avoid deadlocks at this stage of application we have done few steps to lessen the impact. We have added retries after...
4
by: WangKhar | last post by:
Gents, I have come into a system that uses a secondary table to generate (for want of a better word) Identities. eg create table myidents ( name sysname not null, ident int not null)
1
by: Matt White | last post by:
We've found deadlocks in the trace file that were not captured by our Powerbuilder application. Some deadlocks are trapped or, at least, reported to the user as a db error, and others are...
4
by: T Dubya | last post by:
We're experiencing a large number of deadlocks since we began running SQL Server 2000 Enterprise Edition SP3 on a Dell 6650 with hyper threading intel processors. We don't have the same problem on...
7
by: Marcus | last post by:
Hello all, I am trying to figure out when it is appropriate to use shared and exclusive locks with InnoDB. Using shared locks (lock in share mode), I can easily create a scenario with 2 clients...
6
by: Greg Stark | last post by:
There's another poster complaining about referential integrity checks causing deadlocks. Unfortunately I've deleted the message so this response (and the archives aren't responding) isn't going to...
4
by: Mark D Powell | last post by:
SQL Server 2000 SP3A Last week one of our processes starting issuing or suffering deadlock detected errors every 15 minutes or so. I have read several articles at MS on the subject. I set a...
3
by: bobdurie | last post by:
Hi, We have a Java application that runs against a variety of backends including Oracle and MSSql 2000 and 2005. Our application has a handful of active tables that are constantly being...
4
by: John Rivers | last post by:
There are many references to deadlock handlers that retry the transaction automatically. But IMO a deadlock is the result of a design flaw that should be fixed. My applications treat...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.