In our application we have use implicit transactions (we have not explicit SqlTransaction instances).
How could we migrate these cases to dotConnect Universal?
Many Thanks
Marco
Implicit transactions
I have tested the following code with dotConnect Universal v 3.20.44. The records are inserted to the database only after executing "COMMIT TRANSACTION;":
Is that what you mean?
Code: Select all
using (UniConnection conn = new UniConnection("Provider=SQL Server;Data Source=MSSQL2008RTM;user id=sa;Initial Catalog=Test;")) {
conn.Open();
UniCommand cmd = conn.CreateCommand();
cmd.CommandText = "SET IMPLICIT_TRANSACTIONS ON;";
cmd.ExecuteNonQuery();
cmd.CommandText = "insert into dept values (50, 'a', 'a');";
int i = cmd.ExecuteNonQuery();
cmd.CommandText = "insert into dept values (60, 'b', 'b');";
int i2 = cmd.ExecuteNonQuery();
if (i == 1 && i2 == 1) {
cmd.CommandText = "COMMIT TRANSACTION;";
cmd.ExecuteNonQuery();
}
}
Hi,
perhaps the effect at database level is that you have tested, but
our code look like this
TransactionOptions txOptions = new TransactionOptions();
txOptions.Timeout = new TimeSpan(0, 1, 00);
txOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
using (TransactionScope transactionSc = new TransactionScope(TransactionScopeOption.Required, txOptions))
{
using (Connection = new SqlConnection("Data Source=MyDataSource;Initial Catalog=MyCatalog;User ID=MyUserID;Password=MyPassword"))
{
Connection.Open();
try
{
........(DoSomething).......
transactionSc.Complete();
}
finally
{
Connection.Close();
}
}
}
Thanks, Marco
perhaps the effect at database level is that you have tested, but
our code look like this
TransactionOptions txOptions = new TransactionOptions();
txOptions.Timeout = new TimeSpan(0, 1, 00);
txOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
using (TransactionScope transactionSc = new TransactionScope(TransactionScopeOption.Required, txOptions))
{
using (Connection = new SqlConnection("Data Source=MyDataSource;Initial Catalog=MyCatalog;User ID=MyUserID;Password=MyPassword"))
{
Connection.Open();
try
{
........(DoSomething).......
transactionSc.Complete();
}
finally
{
Connection.Close();
}
}
}
Thanks, Marco