C# ADO.NET Transaction Scope Auto Committed Before Calling Complete()

43 Views Asked by At
using (TransactionScope scope = new TransactionScope())
{
    try
    {
        using (OleDbConnection myCon = new OleDbConnection(db2ConnectionString))
        {
            myCon.Open();

            OleDbCommand cmd = new OleDbCommand
                                   {
                                       CommandType = CommandType.Text,
                                       CommandText = insertQuery, // INSERT QUERY
                                       Connection = myCon
                                   };

            _ = cmd.ExecuteNonQuery();

            scope.Complete();
        }
    }
    catch (Exception ex)
    {
        throw;
    }
}
  1. Run the C# code with DB2 connection string
  2. Before calling scope.complete() method, the inserted value is committed in DB2 and able to be seen by querying in the DB2 table
  3. But the similar code for SQL connection works well
0

There are 0 best solutions below