Hi,
I'm getting a deadlock on my database.
Let me first tell you that this is a test database on a Win XP
Professional.
The SP where I'm getting the deadlock is this:
PROCEDURE UpdateTestFields
@id_Test int,
@name varchar(255),
@value varchar(5000),
@lastModifiedBy varchar(50)
AS
UPDATE TestFields
SET value = @value,
lastModifiedBy = @lastModifiedBy,
lastModified = GETDATE()
WHERE id_Test = @id_Test
AND name = @name
Simple, but I'm doing the transaction part in .net
Here's the code:
Public Sub UpdateTestAndTestFields(ByVal intTestId As Int32, ByVal
oParent As Control, ByVal intApplicationNumber As Int32, _
ByVal intCustomerId As Int32, ByVal strLastModifiedBy
As String, ByVal strRemarks As String, _
ByVal enStatus As TestStatus, ByVal blnBlockUser As
Boolean, ByVal enBlockType As BlockType, _
ByVal strUnitNumber As String, ByVal strStationNumber
As String, ByVal strDistrictNumber As String, ByVal strDXName As
String)
Dim conn As New
SqlConnection(ConfigurationSettings.AppSettings("C onnectionstring"))
Dim cmd As New SqlCommand
Dim oTrans As SqlTransaction
conn.Open()
cmd.Connection = conn
oTrans = conn.BeginTransaction
cmd.Transaction = oTrans
cmd.CommandType = CommandType.StoredProcedure
Try
For Each oControl As Control In oParent.Controls
cmd.Parameters.Clear()
Select Case oControl.GetType.Name
Case "TextBox"
Dim txtTemp As New TextBox
txtTemp = oControl
UpdateTestFieldsTrans(conn, cmd, intTestId,
txtTemp.ID, txtTemp.Text, strLastModifiedBy)
Case "RadioButtonList"
Dim rdoTemp As New RadioButtonList
rdoTemp = oControl
UpdateTestFieldsTrans(conn, cmd, intTestId,
rdoTemp.ID, rdoTemp.SelectedItem.Value, strLastModifiedBy)
End If
Case "CheckBox"
Dim chkTemp As New CheckBox
chkTemp = oControl
UpdateTestFieldsTrans(conn, cmd, intTestId,
chkTemp.ID, chkTemp.Checked, strLastModifiedBy)
End Select
Next
cmd.Parameters.Clear()
UpdateTestsTrans(conn, cmd, intCustomerId, intTestId,
enStatus, strRemarks, strLastModifiedBy, blnBlockUser, enBlockType,
strUnitNumber, strStationNumber, strDistrictNumber, strDXName)
oTrans.Commit()
Catch ex As Exception
oTrans.Rollback()
Finally
conn.Close()
End Try
End Sub
As you can see I have an ASPX page with either Textbox, RadioButtonList
or CheckBox controls, those contrls' IDs are stored on my TestField
table under the name field, and that's why I'm looping through my
page's fields to update my table with their given value.
The UpdateTestFieldsTrans Sub is only a call to the SP specified at the
beginning, I'm only passing the connection and the command objects to
persist the transaction, and UpdateTestsTrans Sub is a call to a bigger
SP but since the deadlock is not happening there I don't see the use
of making this post even bigger.
Am I getting the deadlock because is a SQL Server on a WInXP Pro?
Is my approach of handling the field values update in .net wrong?
Any help is appreciated 2 1796
if you get a deadlock with a single user (its normal with multiple users and
your code should handle it), then its a coding error. it happens when you
update the database rows with two different connections, but they are not
sharing the same transaction context. this is handled in ado.net with the
transaction object. you probably have a command that is not using the
transaction object your created.
-- bruce (sqlwork.com)
"Hugo Flores" <hu*********@ge.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com... Hi,
I'm getting a deadlock on my database. Let me first tell you that this is a test database on a Win XP Professional.
The SP where I'm getting the deadlock is this:
PROCEDURE UpdateTestFields @id_Test int, @name varchar(255), @value varchar(5000), @lastModifiedBy varchar(50) AS
UPDATE TestFields SET value = @value, lastModifiedBy = @lastModifiedBy, lastModified = GETDATE() WHERE id_Test = @id_Test AND name = @name
Simple, but I'm doing the transaction part in .net
Here's the code:
Public Sub UpdateTestAndTestFields(ByVal intTestId As Int32, ByVal oParent As Control, ByVal intApplicationNumber As Int32, _ ByVal intCustomerId As Int32, ByVal strLastModifiedBy As String, ByVal strRemarks As String, _ ByVal enStatus As TestStatus, ByVal blnBlockUser As Boolean, ByVal enBlockType As BlockType, _ ByVal strUnitNumber As String, ByVal strStationNumber As String, ByVal strDistrictNumber As String, ByVal strDXName As String)
Dim conn As New SqlConnection(ConfigurationSettings.AppSettings("C onnectionstring")) Dim cmd As New SqlCommand
Dim oTrans As SqlTransaction
conn.Open() cmd.Connection = conn oTrans = conn.BeginTransaction cmd.Transaction = oTrans cmd.CommandType = CommandType.StoredProcedure
Try For Each oControl As Control In oParent.Controls cmd.Parameters.Clear() Select Case oControl.GetType.Name Case "TextBox" Dim txtTemp As New TextBox
txtTemp = oControl UpdateTestFieldsTrans(conn, cmd, intTestId, txtTemp.ID, txtTemp.Text, strLastModifiedBy) Case "RadioButtonList" Dim rdoTemp As New RadioButtonList
rdoTemp = oControl UpdateTestFieldsTrans(conn, cmd, intTestId, rdoTemp.ID, rdoTemp.SelectedItem.Value, strLastModifiedBy) End If Case "CheckBox" Dim chkTemp As New CheckBox
chkTemp = oControl UpdateTestFieldsTrans(conn, cmd, intTestId, chkTemp.ID, chkTemp.Checked, strLastModifiedBy) End Select Next cmd.Parameters.Clear() UpdateTestsTrans(conn, cmd, intCustomerId, intTestId, enStatus, strRemarks, strLastModifiedBy, blnBlockUser, enBlockType, strUnitNumber, strStationNumber, strDistrictNumber, strDXName) oTrans.Commit() Catch ex As Exception oTrans.Rollback() Finally conn.Close() End Try
End Sub
As you can see I have an ASPX page with either Textbox, RadioButtonList or CheckBox controls, those contrls' IDs are stored on my TestField table under the name field, and that's why I'm looping through my page's fields to update my table with their given value. The UpdateTestFieldsTrans Sub is only a call to the SP specified at the beginning, I'm only passing the connection and the command objects to persist the transaction, and UpdateTestsTrans Sub is a call to a bigger SP but since the deadlock is not happening there I don't see the use of making this post even bigger.
Am I getting the deadlock because is a SQL Server on a WInXP Pro? Is my approach of handling the field values update in .net wrong?
Any help is appreciated
Thanks for your answer Bruce.
I'm getting it with multiple users.
Now, you say is normal, but there should be a reason why I'm getting
this.
I know about the scenarios where a connection tries to update a
resource taking by another connection. But you'll see in my case a
TestField is based on a Test that a user is taking, therefore, two
different users can't update anybody else's TestFields. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: BlackHawke |
last post by:
Hello!
This is my second post. Ppl really helped me with the first. I hope there
are answers for this one as well
I own a game company (www.aepoxgames.net) releasing the beta for our first...
|
by: Hasan |
last post by:
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...
|
by: Erik Cruz |
last post by:
Hi.
I have an asp.net application running under Windows 2003 Server, IIS 6, for
seven months. Today, suddenly, the application raised an error entitled
"Server too busy". Searching the event...
|
by: dawatson833 |
last post by:
I want to set an alert for a specific table whenever an event has
caused a deadlock to occur on the table.
I understand how to set up an alert. But I don't know which error
number to use for...
|
by: Zeng |
last post by:
Hi,
The bigger my C# web-application gets, the more places I need to put in the
tedious retrying block of code to make sure operations that can run into
database deadlocks are re-run (retried)...
|
by: Grant McLean |
last post by:
Hi
First a simple question ...
I have a table "access_log" that has foreign keys "app_id" and
"app_user_id" that reference the "application_type" and "app_user"
tables. When I insert into...
|
by: Jobs |
last post by:
Download the JAVA , .NET and SQL Server interview with answers
Download the JAVA , .NET and SQL Server interview sheet and rate
yourself. This will help you judge yourself are you really worth of...
|
by: Thomas Lunsford |
last post by:
I have inherited a set of asp pages that I now need to augment. In
order to minimize changes to production code, I would like to make a
"call" to an asp page from a new asp page. Existing code is...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |