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

Oh those Transaction Headaches!

Hi all!

Perhaps a wise soul can help me here. I have an insert routine for an
ASP.Net application and it works fine, but I decided to test the transaction
rollback capabilities by stopping the SQL server when it was just about to
insert the record (I use a breakpoint and then stop the server). What should
have happened is that the transaction is rolled back and my catch block
response.writes the error which would be something about the network
connection.

Unfortunately, within the catch block when it tries to rollback the
transaction I get another error which states

This SqlTransaction has completed; it is no longer usable
Here is the general look of my code
' *** Use SQL commands to directly insert info into DataSource

Dim strConnection As String

Dim objConnection As SqlConnection

Dim objCommand As New SqlCommand()

Dim objTransaction As SqlTransaction

objConnection = New SqlConnection(Application("strConnection"))

Try

objConnection.Open()

objTransaction = objConnection.BeginTransaction()

' *** Create the Command and set its properties

objCommand.Connection = objConnection

objCommand.Transaction = objTransaction

objCommand.CommandText = "sp_LogInsert2"

objCommand.CommandType = CommandType.StoredProcedure

' Set the various Parameters for the stored Procedure

Blah, Blah, Blah

objCommand.ExecuteNonQuery() ' I stop the SQL server just before it
executes this line

objTransaction.Commit()

Catch objError As Exception

'Error was encountered so roll back all the inserts

objTransaction.Rollback()

' Display error details

Response.write("**** Error while inserting data ****" +
objError.Message + "<br/>" + objError.Source)

Finally

objConnection.Close()

End Try

For some reason many people tell me it has to do with the Try block. Wrox
Professional ASP.Net has many examples of having the BeginTransaction within
the Try block. But just for the sake of argument I moved the Open Connection
and the Begin Transaction outside of the try block. No difference was seen.

Could someone please tell me what I am doing wrong?

Dano
Nov 18 '05 #1
2 2600
I think this is not an ASP.NET question.

The error is telling you, that the transaction is completed. You cannot
rollback (or commit) a transaction that is already complete. It's done.
"Dano" <dt*********@rogers.com> wrote in message
news:P1****************@twister01.bloor.is.net.cab le.rogers.com...
Hi all!

Perhaps a wise soul can help me here. I have an insert routine for an
ASP.Net application and it works fine, but I decided to test the transaction rollback capabilities by stopping the SQL server when it was just about to
insert the record (I use a breakpoint and then stop the server). What should have happened is that the transaction is rolled back and my catch block
response.writes the error which would be something about the network
connection.

Unfortunately, within the catch block when it tries to rollback the
transaction I get another error which states

This SqlTransaction has completed; it is no longer usable
Here is the general look of my code
' *** Use SQL commands to directly insert info into DataSource

Dim strConnection As String

Dim objConnection As SqlConnection

Dim objCommand As New SqlCommand()

Dim objTransaction As SqlTransaction

objConnection = New SqlConnection(Application("strConnection"))

Try

objConnection.Open()

objTransaction = objConnection.BeginTransaction()

' *** Create the Command and set its properties

objCommand.Connection = objConnection

objCommand.Transaction = objTransaction

objCommand.CommandText = "sp_LogInsert2"

objCommand.CommandType = CommandType.StoredProcedure

' Set the various Parameters for the stored Procedure

Blah, Blah, Blah

objCommand.ExecuteNonQuery() ' I stop the SQL server just before it
executes this line

objTransaction.Commit()

Catch objError As Exception

'Error was encountered so roll back all the inserts

objTransaction.Rollback()

' Display error details

Response.write("**** Error while inserting data ****" +
objError.Message + "<br/>" + objError.Source)

Finally

objConnection.Close()

End Try

For some reason many people tell me it has to do with the Try block. Wrox
Professional ASP.Net has many examples of having the BeginTransaction within the Try block. But just for the sake of argument I moved the Open Connection and the Begin Transaction outside of the try block. No difference was seen.
Could someone please tell me what I am doing wrong?

Dano

Nov 18 '05 #2
you cannot roll the transaction back because you lost the connection and
there is no way to notify sqlserver to rollback (it will on its own). there
are other cases when rollbacks will fail, such as when the transaction did a
rollback on its own.

-- bruce (sqlwork.com)
"Dano" <dt*********@rogers.com> wrote in message
news:P1****************@twister01.bloor.is.net.cab le.rogers.com...
Hi all!

Perhaps a wise soul can help me here. I have an insert routine for an
ASP.Net application and it works fine, but I decided to test the transaction rollback capabilities by stopping the SQL server when it was just about to
insert the record (I use a breakpoint and then stop the server). What should have happened is that the transaction is rolled back and my catch block
response.writes the error which would be something about the network
connection.

Unfortunately, within the catch block when it tries to rollback the
transaction I get another error which states

This SqlTransaction has completed; it is no longer usable
Here is the general look of my code
' *** Use SQL commands to directly insert info into DataSource

Dim strConnection As String

Dim objConnection As SqlConnection

Dim objCommand As New SqlCommand()

Dim objTransaction As SqlTransaction

objConnection = New SqlConnection(Application("strConnection"))

Try

objConnection.Open()

objTransaction = objConnection.BeginTransaction()

' *** Create the Command and set its properties

objCommand.Connection = objConnection

objCommand.Transaction = objTransaction

objCommand.CommandText = "sp_LogInsert2"

objCommand.CommandType = CommandType.StoredProcedure

' Set the various Parameters for the stored Procedure

Blah, Blah, Blah

objCommand.ExecuteNonQuery() ' I stop the SQL server just before it
executes this line

objTransaction.Commit()

Catch objError As Exception

'Error was encountered so roll back all the inserts

objTransaction.Rollback()

' Display error details

Response.write("**** Error while inserting data ****" +
objError.Message + "<br/>" + objError.Source)

Finally

objConnection.Close()

End Try

For some reason many people tell me it has to do with the Try block. Wrox
Professional ASP.Net has many examples of having the BeginTransaction within the Try block. But just for the sake of argument I moved the Open Connection and the Begin Transaction outside of the try block. No difference was seen.
Could someone please tell me what I am doing wrong?

Dano

Nov 18 '05 #3

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

Similar topics

2
by: Tim Callaghan | last post by:
We have an inhouse replication process which is causing us headaches when we try to run more than one copy of it against the same target database (we support unlimited remote databases so we may...
1
by: Avanish Pandey | last post by:
Hello All We have 3 differen services (in 3 different server) Service A,B,C . We want to implement distributed transaction when call methods of B and C from A. Is it possible? if yes then how? ...
2
by: John Lee | last post by:
Hi, I have few questions related to .NET 2.0 TransactionScope class behavior: 1. Check Transaction.Current.TransactionInformation.DistributedIdentifier to identify if distributed transaction...
2
by: Tim Callaghan | last post by:
We have an inhouse replication process which is causing us headaches when we try to run more than one copy of it against the same target database (we support unlimited remote databases so we may...
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
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
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
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
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...
0
agi2029
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 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.