SapientGuardian / mysql-connector-net-netstandard

ADO.NET driver for MySQL targeted against netstandard 1.3
GNU General Public License v2.0
46 stars 15 forks source link

Can't get transactions working #10

Closed IntelOrca closed 8 years ago

IntelOrca commented 8 years ago

I am having trouble getting transactions working, the following code:

using (var conn = new MySqlConnection(connString))
{
    conn.Open();
    using (conn.BeginTransaction())
    {
        Console.WriteLine("Test");
    }
}

gives this exception:

Unhandled Exception: MySql.Data.MySqlClient.MySqlException: PROCEDURE mydb.BEGIN does not exist
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
   at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
   at MySql.Data.MySqlClient.MySqlConnection.BeginTransaction(IsolationLevel iso)
   at ConsoleApplication.Program.Main(String[] args)
SapientGuardian commented 8 years ago

Sure enough, it looks like it just tries to execute the word "BEGIN" at https://github.com/SapientGuardian/mysql-connector-net-netstandard/blob/6.9_netstandard/Source/MySql.Data/Connection.cs#L391

My guess is that either the server is not being put in the right state to understand that, or it's never supposed to get there (perhaps it's supposed to be caught by a CommandInterceptor). I see we have MySqlPromotableTransaction ifdef'd out, but I can't actually find any references to it, so that may be a red herring.

Probably the easiest way to track down this one would be to build the upstream source, run that same simple test, and follow BeginTransaction down the stack to see where it diverges. I think I'll have time to do that this weekend if nobody beats me to it.

IntelOrca commented 8 years ago

@SapientGuardian thanks, I have uploaded a test project which builds for both net46 (with MySql.Data) and netcoreapp1.0 (with SapientGuardian.MySql.Data).

testproj.zip

SapientGuardian commented 8 years ago

Found the problem - There's a list of keywords that's supposed to be in the resources, which we lost in the conversion. Since it isn't finding "BEGIN" in our empty list, it thinks it's a stored procedure and is actually executing "call BEGIN" instead of just "BEGIN". I'll fix this, but note that we have so much transaction stuff ifdef'd out that YMMV even after I fix this bug.

IntelOrca commented 8 years ago

It looks like the transaction classes are just small wrapper classes that do the BEGIN, ROLLBACK and COMMIT commands etc. Hopefully there isn't much else to it, at least for what I need it for.