microsoft / referencesource

Source from the Microsoft .NET Reference Source that represent a subset of the .NET Framework
https://referencesource.microsoft.com/
MIT License
3.13k stars 1.26k forks source link

C# ADO.NET (System.Data.OleDb) Transaction Scope Auto Committed Before Calling Complete() #193

Open ras90it opened 10 months ago

ras90it commented 10 months ago

`string sqlConnectionString = ""; // CONNECTION_STRING 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;
}

}`

Reproduction Steps:-

  1. Run the C# code with the DB2 Connection String.
  2. Before Calling scoep.complete() method, the inserted value is committed in DB2 and able to be seen by querying in the DB2 table.
svick commented 10 months ago

This repo is not a good place for asking this kind of question. I think something like Stack Overflow has a much better chance of getting you the answer you're looking for.