Quantcast
Channel: MySQL Forums - Connector/NET and C#, Mono, .Net
Viewing all articles
Browse latest Browse all 1451

Nested transactions (no replies)

$
0
0
I am trying to use a transaction scope to roll back changes in a database. Within the transaction scope I would like to be able to use SubmitChanges, but when I do I get an error message complaining that nested transactions are not supported. I had understood that within a transaction scope SubmitChanges would not create a new transaction scope. I have also downloaded version 6.3.5 of MySQL Connector Net, which should support nested transactions anyway.

By using a MySqlCommand I can avoid these problems, and I have the following code which works:

using (var scope = new TransactionScope())
using (cnxn = new MySqlConnection(@"Database=timesheet;Data Source=jason;User Id=alice;Password=password"))
{
cnxn.Open();
var ts = new TimeSheet.Database.TimeSheet(cnxn);
MySqlCommand command = new MySqlCommand("INSERT INTO Company (name) Values ('Alice')", cnxn);
command.ExecuteNonQuery();
}

I would like to be able to write this code in the following way:

using (var scope = new TransactionScope())
using (cnxn = new MySqlConnection(@"Database=timesheet;Data Source=jason;User Id=alice;Password=password"))
{
cnxn.Open();
var ts = new TimeSheet.Database.TimeSheet(cnxn);
ts.Company.InsertOnSubmit(new TimeSheet.Database.Company() { Name = "Alice", Project = new DbLinq.Data.Linq.EntitySet<TimeSheet.Database.Project>() });
ts.SubmitChanges(System.Data.Linq.ConflictMode.FailOnFirstConflict);
}

However, when I run this code I get the following error:

'System.InvalidOperationException: Nested transactions are not supported.
at MySql.Data.MySqlClient.MySqlConnection.BeginTransaction(IsolationLevel iso)
at MySql.Data.MySqlClient.MySqlConnection.BeginTransaction()
at MySql.Data.MySqlClient.MySqlConnection.BeginDbTransaction(IsolationLevel isolationLevel)
at System.Data.Common.DbConnection.System.Data.IDbConnection.BeginTransaction()
at DbLinq.Data.Linq.Database.Implementation.DatabaseTransaction..ctor(IDbConnection connection)
at DbLinq.Data.Linq.Database.Implementation.DatabaseContext.Transaction()
at DbLinq.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)'

I'm using version 3.5 of .Net, version 5.1.51 of MySQL database, and version 6.3.5
of MySQL Connector Net.

I've already fixed the following bug : http://bugs.mysql.com/bug.php?id=36326 by removing the query_cache_size option.

Thanks,
Alice

Viewing all articles
Browse latest Browse all 1451

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>