473,395 Members | 1,681 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,395 software developers and data experts.

transactions

I have a small database that I have been testing.
I get an error about a transaction deadlock.
The code is in stored procedures and I added transactions to the sp's
but the error happened again.

I wrapped the whole sp in just one transaction and I don't have any
index on the tables.

When I test just by running a program that sends 3 calls at a time it
will get a deadlocked transaction as I send 6 or 9 at a time.

I am not sure how it can have a deadlocked transaction after I used
transactions(begin and commit) in the sp's.

Steve
Jul 30 '07 #1
4 1999
On Jul 30, 1:17 pm, steven <sfuc...@verizon.netwrote:
I have a small database that I have been testing.
I get an error about a transaction deadlock.
The code is in stored procedures and I added transactions to the sp's
but the error happened again.

I wrapped the whole sp in just one transaction and I don't have any
index on the tables.

When I test just by running a program that sends 3 calls at a time it
will get a deadlocked transaction as I send 6 or 9 at a time.

I am not sure how it can have a deadlocked transaction after I used
transactions(begin and commit) in the sp's.

Steve
You didn't give much info. This might be due to non-availability of
index if you have an update or delete statement in the SP with a
filter. try creating an index on the filter column.

profile deadlock chain event and graph to figure out which object is
causing the event.

Aug 1 '07 #2
dba
Hi Steve,

A transaction holds locks on objects until all operations within the
transaction are committed. If you wrap your entire SP within a
transaction, that means all objects accessed by the SP are blocked
until the SP completes. So, contrary to what you expected, doing so
increases the chances of deadlocks.

Try to limit the operations you enclose in a transaction. If you can
avoid it or if it's not necessary, don't use transactions at all. I
also suggest you create proper indexes on the table. That will improve
io access to it and reduce the amount of time required to lock the
table.

I also suggest you try out the tool called SQL Deadlock Detector. It
monitors your database for locks and deadlocks and
provides complete information on captured events. It tells you
everything you need to know (locked objects, blocked statements,
blocking statements,
etc.) to solve your blocking/deadlock problems. The great thing about
this tool is it's event diagram which makes it exremely easy to see
what exactly
is going on.

You can download it from here:
http://lakesidesql.com/downloads/DLD...08-09-2007.zip.

I've been using it for quite a while now (I purchased it) and find it
very handy and useful.

HTH.

On Jul 30, 4:17 pm, steven <sfuc...@verizon.netwrote:
I have a small database that I have been testing.
I get an error about a transactiondeadlock.
The code is in stored procedures and I added transactions to the sp's
but the error happened again.

I wrapped the whole sp in just one transaction and I don't have any
index on the tables.

When I test just by running a program that sends 3 calls at a time it
will get a deadlocked transaction as I send 6 or 9 at a time.

I am not sure how it can have a deadlocked transaction after I used
transactions(begin and commit) in the sp's.

Steve

Aug 17 '07 #3
On Jul 30, 3:17 am, steven <sfuc...@verizon.netwrote:
I have a small database that I have been testing.
I get an error about a transaction deadlock.
The code is in stored procedures and I added transactions to the sp's
but the error happened again.

I wrapped the whole sp in just one transaction and I don't have any
index on the tables.

When I test just by running a program that sends 3 calls at a time it
will get a deadlocked transaction as I send 6 or 9 at a time.

I am not sure how it can have a deadlocked transaction after I used
transactions(begin and commit) in the sp's.

Steve
Steve,

the following article will be useful:

http://www.devx.com/CoDe%20Magazine/...17447/0/page/7

Alex Kuznetsov, SQL Server MVP
http://sqlserver-tips.blogspot.com/

Aug 17 '07 #4
(db*@sql-labs.com) writes:
A transaction holds locks on objects until all operations within the
transaction are committed. If you wrap your entire SP within a
transaction, that means all objects accessed by the SP are blocked
until the SP completes. So, contrary to what you expected, doing so
increases the chances of deadlocks.
Note that this depends on the kind of access. The default isoaltion
level in SQL Server is READ COMMITTED, so as long as you are only
reading rows, the transaction does not matter in any direction.
Try to limit the operations you enclose in a transaction. If you can
avoid it or if it's not necessary, don't use transactions at all.
For updates you should always identify operations that needs to be
performed as a unit, to make sure that your database does not have
inconsistent data. This is a goal which is more than important than
avoiding deadlocks.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Aug 17 '07 #5

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

Similar topics

6
by: Christopher J. Bottaro | last post by:
Hi, Why is there no support for explicit transactions in the DB API? I mean like transaction() to start the trans and commit() and rollback() would end the trans or something. The reason why I...
7
by: Richard Maher | last post by:
Hi, I am seeking the help of volunteers to test some software that I've developed which facilitates distributed two-phase commit transactions, encompassing any resource manager (e.g. SQL/Server...
3
by: Iain Mcleod | last post by:
I wish to do a series of inserts on a sql server database in the context of a transaction. The inserts will be done as a series of stored procedure calls. I wish to be able to rollback any...
6
by: Terri | last post by:
I have a table called Transactions with 3 fields: ID, Date, and Amount. Each ID can have multiple transactions in one particular year. An ID might not have had any transactions in recent years. ...
9
by: TD | last post by:
I am trying to add transactions to my code. The original code worked fine until I followed an example to setup transactions, now the code does strange things, but no error messages. Could...
11
by: Mike P | last post by:
I've been using C# transactions for a while and had no problems with them. Using try catch blocks I can trap basically all possible errors and rollback all necessary data. Over the last few...
1
by: mark | last post by:
In Java, you can use JBoss or similar to host EJB that will manage your transactions for you. You could, of course, write your own transactions using JDBC. In .NET, we can specify our own...
0
radcaesar
by: radcaesar | last post by:
Customer Table ID Name Address City Phone 1 Vijay Stores 6,Gandhi Road Pondy 0413-276564 2 Ram Stores 3, MG Road, Pondicherry 0413-29543756 3 Balu Papers 3, RG...
2
by: Sridhar | last post by:
Hi, I am trying to implement sql transactions. But I am not knowing how to do that. I created a data access layer which contains methods to select/insert/update tables in a database. I have also...
12
by: Rami | last post by:
I have some requirement for an automated payment system. The system has four machines setup as follows: 1- Two machines have a clustered database. 2- Two machines have a .net business logic...
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: 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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.