public void Transaction_Rollback_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.Rollback(); 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 RenameColumnQuery() { try { JetConnection.ClearAllPools(); File.Delete("AdoxTest.accdb"); } catch (Exception e) { Console.WriteLine(e); } AdoxWrapper.CreateEmptyDatabase(JetConnection.GetConnectionString("AdoxTest.accdb")); using (JetConnection connection = new JetConnection(JetConnection.GetConnectionString("AdoxTest.accdb"))) { connection.Open(); CreateTable(connection); CheckColumnExists(connection, "tableName", "columnName"); connection.CreateCommand("rename column tableName.columnName to newColumnName").ExecuteNonQuery(); connection.Close(); JetConnection.ClearAllPools(); connection.Open(); CheckColumnExists(connection, "tableName", "newColumnName"); } JetConnection.ClearAllPools(); File.Delete("AdoxTest.accdb"); }
public void OpenSeveralTimes() { JetConnection connection = new JetConnection(ConnectionString); connection.Open(); connection.Open(); }
//[TestMethod] public void RenameIndexAdox() { try { JetConnection.ClearAllPools(); File.Delete("AdoxTest.accdb"); } catch (Exception e) { Console.WriteLine(e); } AdoxWrapper.CreateEmptyDatabase(JetConnection.GetConnectionString("AdoxTest.accdb")); using (JetConnection connection = new JetConnection(JetConnection.GetConnectionString("AdoxTest.accdb"))) { connection.Open(); CreateTable(connection); CheckIndexExists(connection, "indexName"); AdoxWrapper.RenameIndex(JetConnection.GetConnectionString("AdoxTest.accdb"), "tableName", "indexName", "newIndexName"); connection.Close(); connection.Open(); CheckIndexExists(connection, "newIndexName"); } JetConnection.ClearAllPools(); File.Delete("AdoxTest.accdb"); }
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 Raise_Events() { var stateChangeCount = 0; using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory)); connection.StateChange += (sender, args) => { Console.WriteLine($"{args.OriginalState} => {args.CurrentState}"); stateChangeCount++; }; connection.Open(); using var command = connection.CreateCommand("select * from MSysAccessStorage"); var dataReader = command.ExecuteReader(); while (dataReader.Read()) { } connection.Close(); connection.Open(); connection.Dispose(); Assert.AreEqual(4, stateChangeCount); }
public void GetSchema_From_Open_Connection() { using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory)); connection.Open(); connection.GetSchema(); connection.Close(); }
public void Read_Database_From_Open_Connection() { JetConnection connection = new JetConnection(ConnectionString); connection.Open(); Assert.IsTrue(connection.Database == string.Empty); }
public static JetConnection CreateAndOpenJetDatabase(string storeName = null) { var connection = new JetConnection(CreateJetDatabase(storeName)); connection.Open(); return(connection); }
public void ShowWhere() { int exists = 0; int notExists = 0; using (new Timer("ShowWhere")) using (JetConnection connection = JetDatabaseFixture.GetConnection()) { connection.Open(); for (int i = 0; i < 1000; i++) { if (TableExistsShowWhere(connection, $"Employees_{i % 500}")) { exists++; } else { notExists++; } } } Assert.AreEqual(600, exists); Assert.AreEqual(400, notExists); }
public void CreateDatabaseWithWrongPassword() { using var connection = new JetConnection(Helpers.DataAccessProviderFactory); var command = connection.CreateCommand(); command.CommandText = $"CREATE DATABASE '{StoreName}' PASSWORD 'wrong password'"; command.ExecuteNonQuery(); Assert.IsTrue(File.Exists(StoreName)); var csb = Helpers.DataAccessProviderFactory.CreateConnectionStringBuilder(); csb.SetDataSource(StoreName); csb.SetDatabasePassword("right password"); connection.ConnectionString = csb.ConnectionString; try { connection.Open(); } catch (Exception e) { Assert.IsInstanceOfType(e, typeof(DbException)); } }
public void Read_DataSource_From_Open_Connection() { JetConnection connection = new JetConnection(ConnectionString); connection.Open(); Assert.AreEqual(FileName, connection.DataSource); }
public void Read_ConnectionString_From_Open_Connection() { JetConnection connection = new JetConnection(ConnectionString); connection.Open(); Assert.AreEqual(ConnectionString, connection.ConnectionString); }
public void Change_ConnectionString_From_Open_Connection() { JetConnection connection = new JetConnection(ConnectionString); connection.Open(); connection.ConnectionString = ConnectionStringDummy; }
public void Run() { try { for (var i = 0; i < 100; i++) { using var connection = new JetConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Northwind.accdb"); connection.Open(); for (var j = 0; j < 2000; j++) { Console.WriteLine($"{i:00}: {j:000}"); // // Select_Union: // using (var command1 = connection.CreateCommand()) { command1.CommandText = @"SELECT `c`.`Address` FROM `Customers` AS `c` WHERE `c`.`City` = 'Berlin' UNION SELECT `c0`.`Address` FROM `Customers` AS `c0` WHERE `c0`.`City` = 'London'"; using (var dataReader1 = command1.ExecuteReader()) { while (dataReader1.Read()) { } } } // // Select_bool_closure: // using (var command2 = connection.CreateCommand()) { command2.CommandText = @"SELECT 1 FROM `Customers` AS `c`"; using (var dataReader2 = command2.ExecuteReader()) { while (dataReader2.Read()) { } } } } } } catch (AccessViolationException e) { Console.WriteLine(e); Console.ReadKey(true); } }
public void Change_Database_From_Open_Connection() { JetConnection connection = new JetConnection(ConnectionString); connection.Open(); connection.ChangeDatabase("abcd"); }
public void Read_ServerVersion_From_Open_Connection() { JetConnection connection = new JetConnection(ConnectionString); connection.Open(); Console.WriteLine(connection.ServerVersion); }
public static JetConnection CreateAndOpenDatabase(string storeName) { CreateDatabase(storeName); var connection = new JetConnection(storeName); connection.Open(); return(connection); }
public void Read_ConnectionString_From_Open_Connection() { var connectionString = JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory); using var connection = new JetConnection(connectionString); connection.Open(); Assert.AreEqual(connectionString, connection.ConnectionString); }
public void Transaction_Execute_Close_Open() { DbCommand command; JetConnection connection = new JetConnection(ConnectionString); connection.Open(); var transaction = connection.BeginTransaction(); command = connection.CreateCommand("INSERT INTO SimpleTable(Col) VALUES ('aaa')"); command.Transaction = transaction; command.ExecuteScalar(); connection.Close(); connection.Open(); command = connection.CreateCommand("Select count(*) from SimpleTable"); Assert.AreEqual(0, command.ExecuteScalar()); }
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 GetSchema_From_Open_Connection() { JetConnection connection = new JetConnection(ConnectionString); connection.Open(); connection.GetSchema(); connection.Close(); }
public void GetDataReader_From_Open_Connection() { JetConnection connection = new JetConnection(ConnectionString); connection.Open(); var dataReader = connection.CreateCommand("Select * from MSysAccessStorage").ExecuteReader(); while (dataReader.Read()) { } }
public void Transaction_Execute_Close_Open() { using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory)); connection.Open(); using var transaction = connection.BeginTransaction(); using (var command = connection.CreateCommand("INSERT INTO SimpleTable(Col) VALUES ('aaa')")) { command.Transaction = transaction; command.ExecuteScalar(); } connection.Close(); connection.Open(); using (var command = connection.CreateCommand("select count(*) from SimpleTable")) { Assert.AreEqual(0, command.ExecuteScalar()); } }
public void GetDataReader_From_Open_Connection() { using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory)); connection.Open(); var dataReader = connection.CreateCommand("select * from MSysAccessStorage") .ExecuteReader(); while (dataReader.Read()) { } }
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_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 GetDataReader_From_Open_Connection() { using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory), Helpers.DataAccessProviderFactory); connection.Open(); var dataReader = connection.CreateCommand($"select * from `{JetConnection.DefaultDualTableName}`") .ExecuteReader(); while (dataReader.Read()) { } }
public void Cleanup() { using (JetConnection connection = JetDatabaseFixture.GetConnection()) { connection.Open(); for (int i = 0; i < 300; i++) { string sql = $@"DROP TABLE [Employees_{i}]"; connection.CreateCommand(sql).ExecuteNonQuery(); } } }
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(); } }