I have code which could be executed using a Provider that doesn't support transactions, or doesn't support nested transactions.
How would I programmatically determine such support?
E.g. The code below throws a System.InvalidOperationException on the final commit when using the MySQL .NET Connector, but works fine for MSSQL.
I'd like to be able to alter the code to accommodate various providers, without having to hardcode tests based on the type of provider (E.g. I don't want to have to do if(typeof(connection) == "some provider name")
)
using (IDbConnection connection = Use.Connection(ConnectionStringName))
using (IDbTransaction transaction = connection.BeginTransaction())
{
using (currentCommand = connection.CreateCommand())
{
using (IDbCommand cmd = connection.CreateCommand())
{
currentCommand = cmd;
currentCommand.Transaction = transaction;
currentCommand.ExecuteNonQuery();
}
if (PipelineExecuter.HasErrors)
{
transaction.Rollback();
}
else
{
transaction.Commit();
}
}
transaction.Commit();
}