public void Transaction_Commit_Transaction() { using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory)); connection.Open(); using var firstTransaction = connection.BeginTransaction(); using (var command = connection.CreateCommand("select count(*) from SimpleTable")) { command.Transaction = firstTransaction; command.ExecuteScalar(); } firstTransaction.Commit(); using var secondTransaction = connection.BeginTransaction(); using (var command = connection.CreateCommand("select count(*) from SimpleTable")) { command.Transaction = secondTransaction; command.ExecuteScalar(); } connection.Close(); connection.Open(); using (var command = connection.CreateCommand("select count(*) from SimpleTable")) { command.ExecuteScalar(); } }
public void Transaction_Rollback_Transaction() { DbCommand command; JetConnection connection = new JetConnection(ConnectionString); connection.Open(); DbTransaction firstTransaction = connection.BeginTransaction(); command = connection.CreateCommand("Select count(*) from SimpleTable"); command.Transaction = firstTransaction; command.ExecuteScalar(); firstTransaction.Rollback(); DbTransaction secondTransaction = connection.BeginTransaction(); command = connection.CreateCommand("Select count(*) from SimpleTable"); command.Transaction = secondTransaction; command.ExecuteScalar(); connection.Close(); connection.Open(); command = connection.CreateCommand("Select count(*) from SimpleTable"); command.ExecuteScalar(); }
public void Delete_rollback_implicit() { using (var transaction = _connection.BeginTransaction()) { using var deleteCommand = _connection.CreateCommand(); deleteCommand.CommandText = @"delete * from `Cookies` where `Name` = 'Basic'"; deleteCommand.Transaction = transaction; var affected = deleteCommand.ExecuteNonQuery(); Assert.AreEqual(1, affected); } using var verifyCommand = _connection.CreateCommand(); verifyCommand.CommandText = @"select count(*) as `Count` from `Cookies`"; var count = verifyCommand.ExecuteScalar(); Assert.AreEqual(2, count); }
public void Transaction_Execute_Close_Open_Transaction() { DbCommand command; DbTransaction transaction; JetConnection connection = new JetConnection(ConnectionString); connection.Open(); transaction = connection.BeginTransaction(); command = connection.CreateCommand("INSERT INTO SimpleTable(Col) VALUES ('aaa')"); command.Transaction = transaction; command.ExecuteScalar(); connection.Close(); connection.Open(); transaction = connection.BeginTransaction(); command = connection.CreateCommand("Select count(*) from SimpleTable"); command.Transaction = transaction; Assert.AreEqual(0, command.ExecuteScalar()); }
public void Transaction_Transaction() { using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory)); connection.Open(); using var firstTransaction = connection.BeginTransaction(); using var command = connection.CreateCommand("select count(*) from SimpleTable"); command.Transaction = firstTransaction; command.ExecuteScalar(); try { using var secondTransaction = connection.BeginTransaction(); } catch (Exception e) { Assert.AreEqual("JetConnection does not support parallel transactions", e.Message); throw; } }
public void Transaction_Execute_Commit_Commit() { using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory)); connection.Open(); using var transaction = connection.BeginTransaction(); using var command = connection.CreateCommand("select count(*) from SimpleTable"); command.Transaction = transaction; command.ExecuteScalar(); transaction.Commit(); transaction.Commit(); }
public void Transaction_Execute_Close_Open_Transaction() { using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory)); connection.Open(); using var transaction1 = connection.BeginTransaction(); using (var command = connection.CreateCommand("INSERT INTO SimpleTable(Col) VALUES ('aaa')")) { command.Transaction = transaction1; command.ExecuteScalar(); } connection.Close(); connection.Open(); using var transaction2 = connection.BeginTransaction(); using (var command = connection.CreateCommand("select count(*) from SimpleTable")) { command.Transaction = transaction2; Assert.AreEqual(0, command.ExecuteScalar()); } }
public void Transaction_Transaction() { DbCommand command; JetConnection connection = new JetConnection(ConnectionString); connection.Open(); DbTransaction firstTransaction = connection.BeginTransaction(); command = connection.CreateCommand("Select count(*) from SimpleTable"); command.Transaction = firstTransaction; command.ExecuteScalar(); try { DbTransaction secondTransaction = connection.BeginTransaction(); } catch (Exception e) { Assert.AreEqual("JetConnection does not support parallel transactions", e.Message); throw; } }
public void Transaction_Execute_Commit_Commit() { DbCommand command; JetConnection connection = new JetConnection(ConnectionString); connection.Open(); DbTransaction transaction = connection.BeginTransaction(); command = connection.CreateCommand("Select count(*) from SimpleTable"); command.Transaction = transaction; command.ExecuteScalar(); transaction.Commit(); transaction.Commit(); connection.Close(); }
public void Transaction_Execute_Close_Open_Execute() { DbCommand command; JetConnection connection = new JetConnection(ConnectionString); connection.Open(); var transaction = connection.BeginTransaction(); command = connection.CreateCommand("Select count(*) from MSysAccessStorage"); command.Transaction = transaction; command.ExecuteScalar(); connection.Close(); connection.Open(); command = connection.CreateCommand("Select count(*) from MSysAccessStorage"); command.ExecuteScalar(); }
public void Transaction_Execute_Close_Open_Execute() { using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory)); connection.Open(); using var transaction = connection.BeginTransaction(); using (var command = connection.CreateCommand("select count(*) from MSysAccessStorage")) { command.Transaction = transaction; command.ExecuteScalar(); } connection.Close(); connection.Open(); using (var command = connection.CreateCommand("select count(*) from MSysAccessStorage")) { command.ExecuteScalar(); } }
public void Transaction_Execute_Commit_Close_Open_Execute() { using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory)); connection.Open(); using var transaction = connection.BeginTransaction(); using (var command = connection.CreateCommand($"select count(*) from `{JetConnection.DefaultDualTableName}`")) { command.Transaction = transaction; command.ExecuteScalar(); } transaction.Commit(); connection.Close(); connection.Open(); using (var command = connection.CreateCommand($"select count(*) from `{JetConnection.DefaultDualTableName}`")) { command.ExecuteScalar(); } }
public void UpdateTestWithTransactionsRun() { var queries = Helpers.GetQueries(Properties.Resources.UpdateTestQueries); Assert.AreEqual(6, queries.Length); DbDataReader reader; for (var index = 0; index < queries.Length - 2; index++) { var transaction = _connection.BeginTransaction(); var query = queries[index]; reader = Helpers.Execute(_connection, transaction, query); reader?.Dispose(); transaction.Commit(); } reader = Helpers.Execute(_connection, queries[4]); reader.Read(); Assert.AreEqual(1, reader.GetInt32(0)); reader.Dispose(); Helpers.Execute(_connection, queries[5]); }
public void GetTransaction_From_Closed_Connection() { JetConnection connection = new JetConnection(ConnectionString); var transaction = connection.BeginTransaction(); }
public void GetTransaction_From_Closed_Connection() { using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory)); using var transaction = connection.BeginTransaction(); }