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

SQLTransaction rollback problem

I have two SQLConnection objects having the same connection string and
two corresponding SQLCommand objects for each connection object. I am
using SQLTransaction with the first SQLConnection object but the second
SQLConnection object does not have any SQLTransaction object.

I am inserting some data using the two command objects. The problem
happens when I try to do a rollback on the SQLTransaction object. The
rollback happens only before the first insert happens with the second
connection object. After that, the rollback does not happen.

here is the code snippet:

Dim cnTracker As New
SqlConnection(System.Configuration.ConfigurationSe ttings.AppSettings.Item("sqlconntracker"))
Dim cmdTracker As New SqlCommand
Dim transTracker As SqlTransaction

Dim cnError As New
SqlConnection(System.Configuration.ConfigurationSe ttings.AppSettings.Item("sqlconntracker"))
Dim cmdError As New SqlCommand

cnTracker.Open()
cmdTracker.Connection = cnTracker
transTracker = cnTracker.BeginTransaction(IsolationLevel.ReadComm itted)
cmdTracker.Transaction = transTracker

cnError.Open()
cmdError.Connection = cnError

'this gets rolled back correctly
cmdTracker.CommandType = CommandType.Text
cmdTracker.CommandText = "INSERT INTO Table1 (Field1) VALUES(1)"
cmdTracker.ExecuteNonQuery()

cmdError.CommandType = CommandType.StoredProcedure
cmdError.CommandText = "spImportColError"
cmdError.Parameters.Add(New SqlParameter("@DestColName",
enumDestCols.Value))
cmdError.Parameters.Add(New SqlParameter("@tblImp", "tblImport"))
cmdError.Parameters.Add(New SqlParameter("@fldImp", "FieldImport"))
cmdError.ExecuteNonQuery()

'this does NOT gets rolled back!!!!
cmdTracker.CommandType = CommandType.Text
cmdTracker.CommandText = "INSERT INTO Table1 (Field1) VALUES(2)"
cmdTracker.ExecuteNonQuery()

transTracker.Rollback()

Jul 21 '05 #1
2 2000
hi:

both commands should have the same connection and transaction in order for
both to be rolledbacked, in the way you have it right now, those are
independent transactions.

Hope this helps.

"ma*************@gmail.com" wrote:
I have two SQLConnection objects having the same connection string and
two corresponding SQLCommand objects for each connection object. I am
using SQLTransaction with the first SQLConnection object but the second
SQLConnection object does not have any SQLTransaction object.

I am inserting some data using the two command objects. The problem
happens when I try to do a rollback on the SQLTransaction object. The
rollback happens only before the first insert happens with the second
connection object. After that, the rollback does not happen.

here is the code snippet:

Dim cnTracker As New
SqlConnection(System.Configuration.ConfigurationSe ttings.AppSettings.Item("sqlconntracker"))
Dim cmdTracker As New SqlCommand
Dim transTracker As SqlTransaction

Dim cnError As New
SqlConnection(System.Configuration.ConfigurationSe ttings.AppSettings.Item("sqlconntracker"))
Dim cmdError As New SqlCommand

cnTracker.Open()
cmdTracker.Connection = cnTracker
transTracker = cnTracker.BeginTransaction(IsolationLevel.ReadComm itted)
cmdTracker.Transaction = transTracker

cnError.Open()
cmdError.Connection = cnError

'this gets rolled back correctly
cmdTracker.CommandType = CommandType.Text
cmdTracker.CommandText = "INSERT INTO Table1 (Field1) VALUES(1)"
cmdTracker.ExecuteNonQuery()

cmdError.CommandType = CommandType.StoredProcedure
cmdError.CommandText = "spImportColError"
cmdError.Parameters.Add(New SqlParameter("@DestColName",
enumDestCols.Value))
cmdError.Parameters.Add(New SqlParameter("@tblImp", "tblImport"))
cmdError.Parameters.Add(New SqlParameter("@fldImp", "FieldImport"))
cmdError.ExecuteNonQuery()

'this does NOT gets rolled back!!!!
cmdTracker.CommandType = CommandType.Text
cmdTracker.CommandText = "INSERT INTO Table1 (Field1) VALUES(2)"
cmdTracker.ExecuteNonQuery()

transTracker.Rollback()

Jul 21 '05 #2
I do not want the second connection in a transaction and I do NOT want
to roll back any changes on the second connection object. The issue is
that the inserts that are executed using the first connection object
(within the transaction) before the insert on the second connection
object get rolled back but NOT the inserts executed on the first
connection object but after the insert on the second connection object!

Jul 21 '05 #3

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

Similar topics

2
by: mahajan.sanjeev | last post by:
Hi, I am having problems with rollback using the SQLTransaction object. I am trying to insert records in two tables in a transaction. I want to rollback all the changes if any exception occurs...
3
by: Junyin.Wu | last post by:
what is difference between SqlTransaction and T-Sql(begin tran, commit tran, rollback tran) thanks.
5
by: Swami Muthuvelu | last post by:
Hi, I using command builder to generate my insert, update and delete statements..something like, data_adapter = New SqlClient.SqlDataAdapter(SQL, ActiveConnection) command_builder = New...
2
by: mahajan.sanjeev | last post by:
I have two SQLConnection objects having the same connection string and two corresponding SQLCommand objects for each connection object. I am using SQLTransaction with the first SQLConnection object...
0
by: eric.goforth | last post by:
Hello, I have a subroutine similar to the following: Private Sub RunUpdateTransaction(ByVal UpdateSQL As String, ByVal UpdateConn As SqlConnection) Dim trnDedupe As SqlTransaction =...
1
by: Jason Huang | last post by:
Hi, In my C# Windows form project, how do I know a specific SqlTransaction's status? e.g., the transaction is rollbacked or commited. Thanks for help. Jason
2
by: samuelberthelot | last post by:
Hello, I have a asp.net application in which users can create content and then save everything to a SQLServer2000 database. When they hit the save button on the form here is what I do : Dim...
15
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hi, This is being called in a C# loop within an ado.net transaction from C# 1.1 code. It is used to write large file data to a SQL Server database in chunks, rather than in one go. I had the...
0
by: shalini | last post by:
hi friends, I am using execute non querry in sqlhelper . No i want to use transaction too in executenonquerry. sql helper have the overloaded function fortransaction with sp. but iam not able to...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.