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(A pplication("str Connection"))
Try
objConnection.O pen()
objTransaction = objConnection.B eginTransaction ()
' *** Create the Command and set its properties
objCommand.Conn ection = objConnection
objCommand.Tran saction = objTransaction
objCommand.Comm andText = "sp_LogInse rt2"
objCommand.Comm andType = CommandType.Sto redProcedure
' Set the various Parameters for the stored Procedure
Blah, Blah, Blah
objCommand.Exec uteNonQuery() ' 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.Messag e + "<br/>" + objError.Source )
Finally
objConnection.C lose()
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 BeginTransactio n 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 2 2630
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*********@ro gers.com> wrote in message
news:P1******** ********@twiste r01.bloor.is.ne t.cable.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(A pplication("str Connection"))
Try objConnection.O pen()
objTransaction = objConnection.B eginTransaction () ' *** Create the Command and set its properties
objCommand.Conn ection = objConnection
objCommand.Tran saction = objTransaction
objCommand.Comm andText = "sp_LogInse rt2" objCommand.Comm andType = CommandType.Sto redProcedure ' Set the various Parameters for the stored Procedure
Blah, Blah, Blah objCommand.Exec uteNonQuery() ' 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.Messag e + "<br/>" + objError.Source ) Finally
objConnection.C lose()
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 BeginTransactio n
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
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*********@ro gers.com> wrote in message
news:P1******** ********@twiste r01.bloor.is.ne t.cable.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(A pplication("str Connection"))
Try objConnection.O pen()
objTransaction = objConnection.B eginTransaction () ' *** Create the Command and set its properties
objCommand.Conn ection = objConnection
objCommand.Tran saction = objTransaction
objCommand.Comm andText = "sp_LogInse rt2" objCommand.Comm andType = CommandType.Sto redProcedure ' Set the various Parameters for the stored Procedure
Blah, Blah, Blah objCommand.Exec uteNonQuery() ' 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.Messag e + "<br/>" + objError.Source ) Finally
objConnection.C lose()
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 BeginTransactio n
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 have to
process in 20 replication files on a Monday morning).
The issue I'm seeing is that computer 1 starts processing in the
inserts/updates and continues through the process.
Computer 2 starts processing inserts/updates fine as well but at...
|
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?
I have read the doc regarding this:
http://www.developer.com/net/asp/article.php/3385631
but it will not work when methods are in different services on
|
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 is used - is it accurate way?
2. I have the following code blocks -
In code block 1, the first check the DistributedIdentifier is ALL 0s so it
|
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 have to
process in 20 replication files on a Monday morning).
The issue I'm seeing is that computer 1 starts processing in the
inserts/updates and continues through the process.
Computer 2 starts processing inserts/updates fine as well but at...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |