Skip to content

Transaction: warnings within a transaction (iE Insert ignore) send command with NULL transaction : ERROR #918

Closed
@ofendt

Description

@ofendt

Within a transaction a INSERT IGNORE get a warning.
Then you get an ERROR:
The transaction associated with this command is not the connection's active transaction; see https://fl.vu/mysql-trans
This is because the SHOW WARNINGS was send without the correct command.transaction set.
My soloution:

internal void FinishQuerying(bool hasWarnings)
	{
		m_session!.FinishQuerying();
		m_activeReader = null;

		if (hasWarnings && InfoMessage is not null)
		{
			var errors = new List<MySqlError>();
			using (var command = new MySqlCommand("SHOW WARNINGS;", this))
			{
			  //**************************************************************//
			  //**************************************************************//
				//** FENDT Transaction has to be set *//
				command.Transaction = CurrentTransaction;
				//** FENDT Transaction has to be set *//
			  //**************************************************************//
			  //**************************************************************//
				using (var reader = command.ExecuteReader())
				{
					while (reader.Read())
						errors.Add(new(reader.GetString(0), reader.GetInt32(1), reader.GetString(2)));
				}
			}
			InfoMessage(this, new MySqlInfoMessageEventArgs(errors));
		}
	}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions