473,386 Members | 1,736 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,386 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 2014
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
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,...
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...

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.