on 2014 Apr 16 2:21 PM
Hi,
We are currently using the .NET OleDB Provider to connect to a SQL Anywhere 11.0.1 database and everything is working fine. We were looking into moving to the SQL Anywhere .NET provider for performance reasons, but we have not been able to get transactions to work like they are for us currently. In the code below we create an SATransaction from the connection and then execute an insert on that transaction. We then call the transaction's Rollback, but the row that we just added is not rolled back. Is there something that we are missing or doing incorrectly?
Imports System.Data
Imports NUnit.Framework
Imports iAnywhere.Data.SQLAnywhere
<TestFixture()>
Public Class TestSQLAnywhereNetProvider
Dim Connection As SAConnection
<SetUp()>
Public Sub Setup()
Connection = New SAConnection("Data Source=Sybase Has4win; UID=<UID>; PWD=<Password>;POOLING=True;")
Connection.InitString = "SET TEMPORARY OPTION CONNECTION_AUTHENTICATION='<Our Authentication Key'"
Connection.Open
End Sub
<TearDown()>
Public Sub TearDown()
Connection.Close
Connection.Dispose
End Sub
<Test()>
Public Sub TestTransactionRollsback()
Dim CountQuery As SACommand = Connection.CreateCommand()
CountQuery.CommandText = "SELECT COUNT(*) FROM DBA.t_version"
Assert.AreEqual(1, CountQuery.ExecuteScalar(), "Number of rows in t_version")
Dim TransactionOne As SATransaction = Connection.BeginTransaction()
Dim Query As SACommand = Connection.CreateCommand
Query.CommandText = String.Format("INSERT INTO DBA.t_version(major, minor, revision, path, cutdate) VALUES('{0}','{1}','{2}', '', '2014-01-01')", 11, 12, 13)
Query.Transaction = TransactionOne
Query.ExecuteNonQuery()
CountQuery.Transaction = TransactionOne
Assert.AreEqual(2, CountQuery.ExecuteScalar(), "Number of rows in t_version")
TransactionOne.Rollback
Assert.AreEqual(1, CountQuery.ExecuteScalar(), "Number of rows in t_version")
End Sub
This test fails on the last assert, because there are two rows in the table.
Thanks,
Request clarification before answering.
OK, so I think I figured it out. I created a C# test just to make sure that that was not the issue and it too failed. I then suspecting the database. In looking at some of the options I noticed that the option chained was turned off. Once I turned that on the tests pass! For some reason the OLEDB provider worked with the Chained option off.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, that's why Breck always recommends to set CHAINED "on" to prevent the obstacles of server-side autocommit mode - glad you got it working:)
FWIW: If you feel you have solved the case, I'd suggest that you turn your own comment into an answer and accept it.
When you enter into transaction mode, the .NET provider sets the isolation level but does nothing about ensuring that chained is "on". The OLE DB provider goes to great lengths to control autocommit behaviour.
User | Count |
---|---|
62 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.