logo
down
shadow

Why might a SqlTransaction fail to commit when the commit function is called?


Why might a SqlTransaction fail to commit when the commit function is called?

By : user2954385
Date : November 22 2020, 01:01 AM
Hope this helps This issue was eventually tracked back to a trigger that had recently been updated to include a transaction.
We solved the issue by removing the transaction from the trigger.
code :


Share : facebook icon twitter icon
SqlCommand.Dispose() before SqlTransaction.Commit()?

SqlCommand.Dispose() before SqlTransaction.Commit()?


By : Savas
Date : March 29 2020, 07:55 AM
wish help you to fix your issue The connection, transaction and command objects are just vehicles to send commands to a database. Once a command is executed the database has received it. Whatever you do with the command object afterwards, dispose it, burn it, or shoot it to the moon, this fact does not change. (It can only be rolled back).
You can create and dispose as many commands as you like within the scope of one SqlConnection (with or without SqlTransaction). And you can start and dispose as many transactions as you like within one SqlConnection. To demonstrate this, see:
code :
using (var conn = new SqlConnection(@"server=(local)\sql2008;database=Junk;Integrated Security=SSPI"))
{
  conn.Open();
  // Repeat this block as often as you like...
  using (var tran = conn.BeginTransaction())
  {
    using (var cmd = new SqlCommand("INSERT INTO Mess VALUES ('mess1')", conn, tran))
    {
      cmd.ExecuteNonQuery(); // Shows in Sql profiler
    }
    tran.Commit(); // Commits
  }
  using (var cmd = new SqlCommand("INSERT INTO Mess VALUES ('mess2')", conn))
  {
    cmd.ExecuteNonQuery(); // Executes and commits (implicit transaction).
  }
}
C# SqlTransaction.Commit does not throw exception

C# SqlTransaction.Commit does not throw exception


By : Excel virgin
Date : March 29 2020, 07:55 AM
With these it helps OK, I've rebuilt project, restarted IIS and MS SQL Server and it started work normaly. I am quite unhappy and worried about such problem in production.
Mirek
C# SqlTransaction.Commit error when being called from Finalize

C# SqlTransaction.Commit error when being called from Finalize


By : Shivranshu Chhuneja
Date : March 29 2020, 07:55 AM
this will help .net gives you no warranty when your destructor/finalizer is called. Your transaction can already time out or be recycled (see comments). I believe you only need to call finalizers in some exotic cases when you need to free unmanaged resources. And even in such situations Dispose mostly works. So use Dispose.
I'm also not sure if commiting transaction even inside Dispose is a good idea. Logically dispose (and finalizer) are designed to free resources. Could be better to do it explicitly.
How does SQLTransaction.Commit() work?

How does SQLTransaction.Commit() work?


By : websuckle
Date : March 29 2020, 07:55 AM
around this issue A few day ago, I have studied SqlTransaction and I know the purpose of SqlTransaction.Commit() - it should "commit the database transaction." - MSDN.
code :
try
{
    using (var conn = new SqlConnection(/* connection string or whatever */))
    {
        conn.Open();

        using (var trans = conn.BeginTransaction())
        {
            try
            {
                using (var cmd = conn.CreateCommand())
                {
                    cmd.Transaction = trans;
                    /* setup command type, text */
                    /* execute command */
                }

                trans.Commit();
            }
            catch (Exception ex)
            {
                trans.Rollback();
                /* log exception and the fact that rollback succeeded */
            }
        }
    }
}
catch (Exception ex)
{
    /* log or whatever */
}
Commit multiple SqlCommands with SqlTransaction

Commit multiple SqlCommands with SqlTransaction


By : user3818126
Date : March 29 2020, 07:55 AM
Does that help so much. I ended up figuring it our on my own based on other peoples combined answers, as a thank you here is the code I used:
code :
public List<Models.eConnectModels.eConnStatus> CommitAsTransaction(List<SqlCommand> commands) {
            SqlTransaction transaction = null;
            SqlConnection connection = null;
            List<eConnStatus> ErrorList = new List<eConnStatus>();
            try {
                connection = this.CreateSqlConnection();
                connection.Open();
                transaction = connection.BeginTransaction(IsolationLevel.ReadUncommitted, "TransactionID");

                foreach (SqlCommand cmd in commands) {
                   eConnStatus curErr = new eConnStatus();
                    cmd.Transaction = transaction;
                    cmd.Connection = connection;
                    SqlParameter errorString = cmd.Parameters.Add("@oErrString", SqlDbType.VarChar);
                    errorString.Direction = ParameterDirection.Output;
                    errorString.Size = 8000;

                    SqlParameter errorStatus = cmd.Parameters.Add("@O_iErrorState", SqlDbType.Int);
                    errorStatus.Direction = ParameterDirection.Output;

                    cmd.ExecuteNonQuery();
                    curErr.ErrorState = (int)cmd.Parameters["@O_iErrorState"].Value;
                    curErr.ErrorMessage = (string)cmd.Parameters["@oErrString"].Value;
                    ErrorList.Add(curErr);
                }

                transaction.Commit();
            }
            catch (Exception ex) {
                transaction.Rollback();
                connection.Close();
                throw ex;
            }
            connection.Close();
            return ErrorList;
        }
Related Posts Related Posts :
  • How to use Addfields in MongoDB C# Aggregation Pipeline
  • MsTest TestCleanup method not called when an unhandled exception is thrown
  • missing last data when exporting gridview to excel
  • How to add array of objects to List in c#
  • Lambda Expression to order (sort) my list collection
  • Library for displaying music notation
  • How to compare two dictionaries in c# and get the output as True and False after validation
  • specify fields to be serialized with JSON
  • How do you obtain the content of a specific node using XmlDocument in C#?
  • How to ignore the first line in a csv file when you read the csv file in C#
  • c# - Problem calling public void from class
  • How to tell a class which objects it should create? Type vs. object confusion :(
  • Save CheckBox state to xml
  • WIX CAQuietExec NETSH Command Fails
  • Issues sending http put request every 60 seconds to RoR app
  • ConfigurationManager.ConnectionStrings.ConnectionString Issue
  • Real size WPF controls for printing
  • How to cancel properly?
  • C# String multiplication error
  • Using Solrnet and Assigning Attributes with Entity Framework Generated POCOs
  • Regex pattern for single backslash
  • TextBox: insert spaces for credit card number?
  • C# DLL loaded for exe-application is not found when launching similar DLL by rundll32.exe
  • Debug a Windows Service with WCF library
  • Open a file from an external assembly?
  • Servicestack RegistrationFeature Unable to bind request
  • Index was outside the bounds of the array confusion
  • Error in Xml to List code. The ':' character, hexadecimal value 0x3A, cannot be included in a name
  • I am trying to do a while loop with a string conditional statement in C#
  • C# 'Cannot access a disposed object. Object name: 'SslStream'.'
  • How to make Gecko use seperate CookieContainer per instance?
  • C# Advanced form "please wait"
  • Send and Receive data C# using network stream
  • How to discover that appsettings changed in C#?
  • Check what needs full trust
  • What is the execution order of an MVC Razor view/layout
  • Table designer (Entity Framework) is too resource intense
  • How to clean up an exception string so it can be displayed via Javascript Alert?
  • Configuring Amazon SES Feedback Notifications via Amazon SNS in ASP.NET MVC (C#)
  • C# api responce and request
  • Dynamodb putitem function not working properly
  • theme in windows phone(light or dark) using c#
  • Backup attached database file(.mdf) using c# and SQL Server
  • What is 'TextFile' and where it is uses in WPF project
  • Using same alias for multiple namespaces
  • how to move mails into separate folders
  • Multithreaded Uploader
  • Memory fragmentation?
  • C# correct exception handling
  • "Could not open macro storage" when accessing using file on another machine
  • How to access other directories of hosted server
  • C# Jagged Array check if value exists/true
  • Why can't I type Clone() properly?
  • exception on accessing dictionary from list
  • Getting the immediate response from server without waiting to 200 message
  • Why am I getting exception Directory Is Not empty?
  • Could not load file or assembly 'CefSharp.dll' or one of its dependencies
  • Sending Email By Using C# in unity3D?
  • Correct usage of await async in webapi
  • Program update code issue
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org