Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MySqlBulkLoader inside Transaction throws InvalidOperationException #300

Closed
alextrukhan opened this issue Jul 25, 2017 · 5 comments
Closed
Assignees
Labels

Comments

@alextrukhan
Copy link

alextrukhan commented Jul 25, 2017

Invokation of MySqlBulkLoader.Load() inside Transaction throws InvalidOperationException with message "The transaction associated with this command is not the connection's active transaction.".

m_database.Connection.Open();
var tr = m_database.Connection.BeginTransaction();
var bl = new MySqlBulkLoader(m_database.Connection)
{
     SourceStream = new MemoryStream(m_memoryStreamBytes),
     TableName = m_testTable,
};
bl.Load();//InvalidOperationException is throwed here
tr.Rollback();

Due to code from MySqlBulkLoader.LoadAsync

                var commandString = BuildSqlCommand();
                var cmd = new MySqlCommand(commandString, Connection)
                {
                    CommandTimeout = Timeout
                };

And code from MySqlCommand.IsValid

		public MySqlCommand(string commandText, MySqlConnection connection, MySqlTransaction transaction)
		{
			CommandText = commandText;
			DbConnection = connection;
			DbTransaction = transaction;
			m_parameterCollection = new MySqlParameterCollection();
			CommandType = CommandType.Text;
		}

And

else if (DbTransaction != Connection.CurrentTransaction)
				exception = new InvalidOperationException("The transaction associated with this command is not the connection's active transaction.");

This exception will be throw always when MySqlBulkLoader.Load will be invoked inside transaction.
There are some workarounds to fix this issue?
Or do I do something wrong?

@bgrainger bgrainger added the bug label Jul 26, 2017
@bgrainger
Copy link
Member

bgrainger commented Jul 26, 2017

I thought I had read in the MySQL manual that LOAD DATA wasn't supported inside a transaction, but I can't find any such restriction now. This sounds like it might be a bug; I'll have to check the actual behaviour of LOAD DATA with COMMIT and ROLLBACK.

@bgrainger bgrainger self-assigned this Jul 26, 2017
@bgrainger
Copy link
Member

bgrainger commented Jul 27, 2017

Fixed in 0.24.0.

@GomesNayagam
Copy link

GomesNayagam commented Nov 17, 2017

@bgrainger @alextruhan looks the issue again opened in 0.31.0, check again.
System.InvalidOperationException: The transaction associated with this command is not the connection's active transaction.

@bgrainger bgrainger reopened this Nov 17, 2017
@bgrainger
Copy link
Member

bgrainger commented Nov 17, 2017

I suspect this is a regression caused by fixing #389.

The previous bug fix was dependent on the order of creation of MySqlBulkLoader and BeginTransaction; you should be able to work around it for now by creating the MySqlBulkLoader inside the transaction.

@bgrainger
Copy link
Member

bgrainger commented Nov 17, 2017

Should be fixed in 0.31.1.

If not, please open a new issue with sample code to reproduce the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants