472,333 Members | 1,024 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,333 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 2463
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...
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...
2
by: John Lee | last post by:
Hi, I have few questions related to .NET 2.0 TransactionScope class behavior: 1. Check...
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...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.