Skip to content

MySqlBulkLoader inside Transaction throws InvalidOperationException #300

@alextrukhan

Description

@alextrukhan

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?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions