Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 571919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:33:31+00:00 2026-05-13T13:33:31+00:00

I have code which could be executed using a Provider that doesn’t support transactions,

  • 0

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();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T13:33:31+00:00Added an answer on May 13, 2026 at 1:33 pm

    There is no built-in way for an ADO.NET provider to give details about what capabilities they provide. SQLite used to not support nested transactions either, but some ADO.NET providers for SQLite would fake it in code (without proper support for savepoints). In that case, you’d never get errors, but you might not get the behavior you expected.

    I also have seen many different implementations of the IDataReader indexer. It used to be that some providers would throw an exception when passed a field name that didn’t exist, and some providers would return null. In ADO.NET 2.0 the help docs were updated to indicate that providers should throw an exception, but without checked exceptions there’s no way to ensure that all providers were properly updated.

    So, in short, The System.Data.Common namespace and various ADO.NET providers make it a lot easier to work with different databases, but you do have to be aware of what DB(s) you’re using and the differences in each provider (most of which will probably be undocumented annoying quirks as opposed to big differences).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say you have a file myfile.php which executes some PHP code. Could this file
Have some Perl code which is using the DBI module - (the code is
I have code which has a drop down list. And when a certain option
I have code which needs to do something like this There is a list
I have code which looks like: private static DirectiveNode CreateInstance(Type nodeType, DirectiveInfo info) {
I have code which as been working against an older Active Directory server and
I have code which performs query on Jboss server. It has JNDI based datasource
I have code which works in all sorts of different situations, including when copying
I already have code which lazy loads scripts on request. My issue now is
Hi I have code which sets up a basic client to server scenario and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.