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 8341895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:37:04+00:00 2026-06-09T05:37:04+00:00

The stored procedure cannot be executed. Can anyone please advise me and point out

  • 0

The stored procedure cannot be executed. Can anyone please advise me and point out my stupid mistake?

The error message that I got is

Invalid operation. The connection is closed

Code:

public void Update(RepliesBAL RPBAL)
{
    using (SqlConnection connection = new SqlConnection(@"Data Source=19NNZP;Initial Catalog=ivr;Persist Security Info=True;User ID=sa;Password=sa"))
    {
        SqlCommand command = new SqlCommand ();
        command.CommandType = CommandType.StoredProcedure;
        command.CommandText = "dbo.fax_UpdateFaxReply";
        command.Parameters.Add("@uid", SqlDbType.VarChar, 50).Value = RPBAL.UlyssesID ;

        SqlTransaction transaction;

        transaction = connection.BeginTransaction("SampleTransaction");

        command.Connection = connection;
        command.Transaction = transaction;

        try
        {
            connection.Open();
            command.ExecuteNonQuery();
            Console.WriteLine("OK");
        }
        catch (Exception ex)
        {
            Console.WriteLine("Commit Exception Type: {0}", ex.GetType());
            Console.WriteLine("  Message: {0}", ex.Message);
            try
            {
                transaction.Rollback();
            }
            catch (Exception ex2)
            {
                Console.WriteLine("Rollback Exception Type: {0}", ex2.GetType());
                Console.WriteLine("  Message: {0}", ex2.Message);
                throw new Exception(ex.Message);
            }
        }
    }
}
  • 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-09T05:37:05+00:00Added an answer on June 9, 2026 at 5:37 am

    In order to call .BeginTransaction(), your connection needs to be opened already – so change your code to:

    using (SqlConnection connection = new SqlConnection(@"Data Source=19NNZP;Initial Catalog=ivr;Persist Security Info=True;User ID=sa;Password=sa"))
    {
            // set up the SqlCommand 
            SqlCommand command = new SqlCommand();
            command.Connection = connection;
            command.CommandType = CommandType.StoredProcedure;
            command.CommandText = "dbo.fax_UpdateFaxReply";
    
            // SqlDbType should be *NVarChar* to exactly match the stored procedure parameter's type! 
            // Otherwise you'll have an implicit conversion happening....
            command.Parameters.Add("@uid", SqlDbType.NVarChar, 50).Value = RPBAL.UlyssesID ;
    
            SqlTransaction transaction;
    
            try
            {
                // open connection, start transaction
                connection.Open();
    
                transaction = connection.BeginTransaction("SampleTransaction");
    
                // assign transaction to SqlCommand and execute it  
                command.Transaction = transaction;
                command.ExecuteNonQuery();
    
                // if successful - commit the transaction!
                transaction.Commit();
                connection.Close();
    
                Console.WriteLine("OK");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Commit Exception Type: {0}", ex.GetType());
                Console.WriteLine("  Message: {0}", ex.Message);
                try
                {
                    transaction.Rollback();
                }
                catch (Exception ex2)
                {
                    Console.WriteLine("Rollback Exception Type: {0}", ex2.GetType());
                    Console.WriteLine("  Message: {0}", ex2.Message);
                    throw new Exception(ex.Message);
                }
            }
        }
    

    After that change, hopefully, this code should work just fine.

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

Sidebar

Related Questions

I'm getting the following error when calling a stored procedure: Cannot find the object
I'm getting following error if i'm running a stored-procedure Cannot insert duplicate key row
I have a stored procedure that returns two int Values. The first can not
I have a MySQL stored procedure that is executed from Python (wrapped in Django).
I have the following stored procedure that I have to get data from: EXECUTE
I have a stored procedure in mysql thats to perform a task that needs
Mysql Version 14.14 Distrib 5.1.41 I have a stored procedure that I am trying
I have a stored procedure that runs the following: 'ALTER LOGIN ' + @Login
I have a stored procedure that returns multiple columns. like colA colB colC ....
I've got a stored procedure that executes some repetitive code, so I decided to

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.