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

  • Home
  • SEARCH
  • 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 8388373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:27:38+00:00 2026-06-09T18:27:38+00:00

Using the following method I am able to run a transaction against an Oracle

  • 0

Using the following method I am able to run a transaction against an Oracle database using ADO.NET. When I try the same code on an SQL Server database I get the error shown. What is the cause of this and how can it be fixed?

The error:

ExecuteNonQuery requires the command to have a transaction when the
connection assigned to the command is in a pending local transaction.
The Transaction property of the command has not been initialized.

The Code:

    /// <summary>
    /// A method to run transactional SQL on a database. Does not return a record set.
    /// </summary>
    /// <param name="transactions">A list of commands</param>
    /// <returns>A boolean indicator of success</returns>
    public bool ExecuteTransactionNonQuery(List<string> transactions)
    {
        if (transactions == null)
        {
            throw new ArgumentNullException("transactions");
        }

        PrepareConnection();

        DbTransaction dbTransaction = DBFactoryDatabaseConnection.BeginTransaction();

        try
        {
            foreach (var transaction in transactions)
            {

                DBFactoryDatabaseCommand.CommandText = transaction;
                DBFactoryDatabaseCommand.CommandType = CommandType.Text;
                DBFactoryDatabaseCommand.ExecuteNonQuery();
            }

            dbTransaction.Commit();
        }
        catch(Exception ex)
        {
            dbTransaction.Rollback();
            try
            {
                Close();
            }
            catch (Exception f)
            {
                throw new Exception("Error: Transaction execute failed on the database. " + ex.Message + ". Following that the application failed to close the connection. " + f.Message + ". ExecuteTransactionNonQuery().");
            }
            throw;
        }
        finally
        {
            dbTransaction.Dispose();
        }

        return true;
    }
  • 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-06-09T18:27:39+00:00Added an answer on June 9, 2026 at 6:27 pm

    You need to assign the transaction to the command.

    DBFactoryDatabaseCommand.Transaction = dbTransaction;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following method in my code: - (NSMutableArray *) newOrderedArray:(NSMutableArray *)array ByKey:(NSString
im using the following method [DllImport(kernel32.dll, SetLastError=true)] static extern int GetProcessId(IntPtr hWnd); to try
I am using following method to get bitmap from url but image is not
I am using the following method to reverse geocode a google maps latlng: [GClientGeocoder.getLocations(address:String,
I am using the following method to basically create a JSON string. var saveData
I am using the following method to get the time of the video with
I am using the following method to serialize a date as a string private
I'm using the following method to open my SQLite db. private void open() {
We are using the following method to write the log to log file. The
So I am creating a container with rounded corners using the following method: div.rounded

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.