.NET Data Providers - How do I determine what they can do?
Posted
by rbellamy
on Stack Overflow
See other posts from Stack Overflow
or by rbellamy
Published on 2010-01-06T22:55:40Z
Indexed on
2010/03/11
21:29 UTC
Read the original article
Hit count: 293
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();
}
© Stack Overflow or respective owner