Ado.Net - Connection.EnlistTransaction

Discussion in 'Databases' started by KenA, Oct 14, 2006.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Suppose I have a method and I now want to use this method to participate in an existing Transaction:



    private static void Insert( string orderId, string cnnStr )
    {
    ...
    SqlConnection oCnn = new SqlConnection( cnnStr );
    oCnn.Open();
    SqlCommand oCmd = new SqlCommand( "usp_Insert", oCnn );
    oCmd.CommandType = CommandType.StoredProcedure;
    oCmd.Parameters.AddWithValue( "@orderId", orderId );
    oCmd.ExecuteNonQuery();
    }Since this method will be part of an existing trans, can I do something like?:



    private static void Insert( string orderId, string cnnStr )
    {
    ...
    SqlConnection oCnn = new SqlConnection( cnnStr );
    oCnn.EnlistTransaction( System.Transactions.Transaction.Current );
    oCnn.Open();
    SqlCommand oCmd = new SqlCommand( "usp_Insert", oCnn );
    oCmd.CommandType = CommandType.StoredProcedure;
    oCmd.Parameters.AddWithValue( "@orderId", orderId );
    oCmd.ExecuteNonQuery();
    }Is that all, or should I find a way to commit the trans?

    »»» Ken.Awamura
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    I don't think this will work on our server. This requires ASP.NET transaction support.

    You should be handling your transaction within your SQL statements.




    Post Edited By Moderator (Joel Thoms) : 10/17/2006 1:49:19 AM GMT
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page