rss
twitter
  •  

Simple Look @ Transaction in ADO.Net

| Posted in Uncategorized |

0

   // C#   
             DbTransaction tx;
             try 
             {
                 conn.Open();
                 tx = conn.BeginTransaction();
                 cmdDeleteOrders.ExecuteNonQuery();
                 cmdDeleteCustomer.ExecuteNonQuery();
                 tx.Commit();
                 conn.Close();
             }
             catch (Exception exception)
             {
                 if (tx != null)
                 {
                     tx.Rollback();
                 }
                 if (conn != null)
                 {
                     if (conn.State != ConnectionState.Closed)
                     {
                         conn.Close();
                     }
                 }
             }

The exception handling can be simplified if the previous code is refactored as shown in this next code. The using statement calls Dispose() on the transaction object. The Dispose method checks to see if there are any uncommitted changes. If there are, it rolls back the transaction

  
              // C#   
             conn.Open();
             using (DbTransaction tx = conn.BeginTransaction())
             {
                 cmdDeleteOrders.ExecuteNonQuery();
                 cmdDeleteCustomer.ExecuteNonQuery();
                 tx.Commit();
                 conn.Close();
             }

Multiple Active Result Set (MARS) @ADO.Net

| Posted in Uncategorized |

1

While my certification study i want to share this information with any one, On a standard connection—that is, one that doesn’t use MARS—it is possible to have only a single open result set at any moment during the lifetime of the connection. This means that should multiple operations be required, the connection must be closed and reopened each time, which can be an expensive process. (ADO.Net MCTS EBook)

but you need to do this by To use MARS, a simple modification to the connection string is required, namely, another name-value pair called MultipleActiveResultSets=true. Look at what happens with this setting enabled