コード例 #1
0
        public void CloseSeveralTimes()
        {
            int           stateChangeCount = 0;
            JetConnection connection       = new JetConnection(ConnectionString);

            connection.StateChange += (sender, args) => {
                Console.WriteLine($"{args.OriginalState} => {args.CurrentState}");
                stateChangeCount++;
            };
            connection.Close();
            connection.Close();
            Assert.AreEqual(0, stateChangeCount);
        }
コード例 #2
0
        public void CloseSeveralTimes()
        {
            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.Close();
            connection.Close();
            Assert.AreEqual(0, stateChangeCount);
        }
コード例 #3
0
        public void Read_ConnectionString_From_Closed1_Connection()
        {
            JetConnection connection = new JetConnection(ConnectionString);

            connection.Close();
            Assert.AreEqual(ConnectionString, connection.ConnectionString);
        }
コード例 #4
0
        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");
        }
コード例 #5
0
        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();
            }
        }
コード例 #6
0
        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();
        }
コード例 #7
0
 public void GetSchema_From_Open_Connection()
 {
     using var connection = new JetConnection(JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory));
     connection.Open();
     connection.GetSchema();
     connection.Close();
 }
コード例 #8
0
        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);
        }
コード例 #9
0
        //[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");
        }
コード例 #10
0
        public void TearDown()
        {
            _schemaOperationsProvider?.Dispose();
            _connection?.Close();

            Helpers.DeleteDatabase(StoreName);
        }
コード例 #11
0
        public void GetSchema_From_Open_Connection()
        {
            JetConnection connection = new JetConnection(ConnectionString);

            connection.Open();
            connection.GetSchema();
            connection.Close();
        }
コード例 #12
0
        public void Read_ConnectionString_From_Closed1_Connection()
        {
            var connectionString = JetConnection.GetConnectionString(StoreName, Helpers.DataAccessProviderFactory);

            using var connection = new JetConnection(connectionString);
            connection.Close();
            Assert.AreEqual(connectionString, connection.ConnectionString);
        }
コード例 #13
0
        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();
        }
コード例 #14
0
        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());
        }
コード例 #15
0
        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();
        }
コード例 #16
0
        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());
            }
        }
コード例 #17
0
        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();
            }
        }
コード例 #18
0
        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();
            }
        }
コード例 #19
0
        public void Raise_Events()
        {
            int stateChangeCount = 0;

            JetConnection connection = new JetConnection(ConnectionString);

            connection.StateChange += (sender, args) => {
                Console.WriteLine($"{args.OriginalState} => {args.CurrentState}");
                stateChangeCount++;
            };

            connection.Open();
            var dataReader = connection.CreateCommand("Select * from MSysAccessStorage").ExecuteReader();

            while (dataReader.Read())
            {
            }
            connection.Close();
            connection.Open();
            connection.Dispose();

            Assert.AreEqual(4, stateChangeCount);
        }
コード例 #20
0
 public void TearDown()
 {
     _connection?.Close();
     Helpers.DeleteDatabase(StoreName);
 }
コード例 #21
0
 private void ReOpenConnection()
 {
     _connection.Close();
     JetConnection.ClearAllPools();
     _connection.Open();
 }