I have a scenario where I need to insert, call and drop a stored procedure in several databases. This is done in a powershell script. I want to be able to roll back the changes made by the stored procedure if some situations occur further down the in the script.
The problem is that I'm not able to roll back the changes made by the stored procedure. The stored procedure is almost 6 KB and does a number of updates and inserts, so I'm wondering if maybe it is too much for the transaction. When only doing the SP call in the transaction, I can roll it back.
Any help would be greatly appreciated.
$cmd = New-Object MySql.Data.MySqlClient.MySqlCommand('', $mysqlConn) $cmd.Transaction = $mysqlConn.BeginTransaction([System.Data.IsolationLevel]'ReadCommitted') $cmd.CommandText = [IO.File]::ReadAllText($mySqlStoredProcedurePath) [Void]$cmd.ExecuteNonQuery() $cmd.CommandText = "CALL storedProcedureX($startHierarchyId)" [Void]$cmd.ExecuteNonQuery() $cmd.CommandText = "DROP PROCEDURE IF EXISTS storedProcedureX" [Void]$cmd.ExecuteNonQuery() $cmd.Transaction.Rollback()