当前位置: 首页>>代码示例>>C#>>正文


C# SqliteConnection.BeginTransaction方法代码示例

本文整理汇总了C#中Microsoft.Data.Sqlite.SqliteConnection.BeginTransaction方法的典型用法代码示例。如果您正苦于以下问题:C# SqliteConnection.BeginTransaction方法的具体用法?C# SqliteConnection.BeginTransaction怎么用?C# SqliteConnection.BeginTransaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Data.Sqlite.SqliteConnection的用法示例。


在下文中一共展示了SqliteConnection.BeginTransaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Ctor_throws_when_invalid_isolation_level

        public void Ctor_throws_when_invalid_isolation_level()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:"))
            {
                connection.Open();

                var ex = Assert.Throws<ArgumentException>(() => connection.BeginTransaction(IsolationLevel.Snapshot));

                Assert.Equal(Strings.FormatInvalidIsolationLevel(IsolationLevel.Snapshot), ex.Message);
            }
        }
开发者ID:carloserodriguez2000,项目名称:Microsoft.Data.Sqlite,代码行数:11,代码来源:SqliteTransactionTest.cs

示例2: CreateShared

        private SqliteTestStore CreateShared(Action initializeDatabase)
        {
            CreateShared(typeof(SqliteTestStore).Name + _name, initializeDatabase);

            _connection = new SqliteConnection(CreateConnectionString(_name));

            _connection.Open();
            _transaction = _connection.BeginTransaction();

            return this;
        }
开发者ID:rbenhassine2,项目名称:EntityFramework,代码行数:11,代码来源:SqliteTestStore.cs

示例3: Ctor_sets_read_uncommitted

        public void Ctor_sets_read_uncommitted()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:;Cache=Shared"))
            {
                connection.Open();

                using (connection.BeginTransaction(IsolationLevel.ReadUncommitted))
                {
                    Assert.Equal(1L, connection.ExecuteScalar<long>("PRAGMA read_uncommitted;"));
                }
            }
        }
开发者ID:carloserodriguez2000,项目名称:Microsoft.Data.Sqlite,代码行数:12,代码来源:SqliteTransactionTest.cs

示例4: Ctor_unsets_read_uncommitted_when_serializable

        public void Ctor_unsets_read_uncommitted_when_serializable()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:"))
            {
                connection.Open();

                using (connection.BeginTransaction(IsolationLevel.Serializable))
                {
                    Assert.Equal(0L, connection.ExecuteScalar<long>("PRAGMA read_uncommitted;"));
                }
            }
        }
开发者ID:carloserodriguez2000,项目名称:Microsoft.Data.Sqlite,代码行数:12,代码来源:SqliteTransactionTest.cs

示例5: IsolationLevel_throws_when_completed

        public void IsolationLevel_throws_when_completed()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:"))
            {
                connection.Open();

                var transaction = connection.BeginTransaction();
                transaction.Dispose();

                var ex = Assert.Throws<InvalidOperationException>(() => transaction.IsolationLevel);

                Assert.Equal(Strings.TransactionCompleted, ex.Message);
            }
        }
开发者ID:carloserodriguez2000,项目名称:Microsoft.Data.Sqlite,代码行数:14,代码来源:SqliteTransactionTest.cs

示例6: Ctor_throws_when_invalid_isolation_level_without_cache

        public void Ctor_throws_when_invalid_isolation_level_without_cache()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:"))
            {
                connection.Open();
                var ex = Assert.Throws<ArgumentException>(() => connection.BeginTransaction(IsolationLevel.ReadUncommitted));
                Assert.Equal(Strings.FormatInvalidIsolationLevelForUnsharedCache(IsolationLevel.ReadUncommitted), ex.Message);
            }

            using (var connection = new SqliteConnection("Data Source=:memory:;Cache=Shared"))
            {
                connection.Open();
                connection.BeginTransaction(IsolationLevel.ReadUncommitted);
            }
        }
开发者ID:carloserodriguez2000,项目名称:Microsoft.Data.Sqlite,代码行数:15,代码来源:SqliteTransactionTest.cs

示例7: Ctor_sets_values

        public void Ctor_sets_values()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:"))
            {
                connection.Open();

                using (var transaction = connection.BeginTransaction())
                {
                    var command = new SqliteCommand("SELECT 1;", connection, transaction);

                    Assert.Equal("SELECT 1;", command.CommandText);
                    Assert.Same(connection, command.Connection);
                    Assert.Same(transaction, command.Transaction);
                }
            }
        }
开发者ID:antiufo,项目名称:Microsoft.Data.Sqlite,代码行数:16,代码来源:SqliteCommandTest.cs

示例8: BeginTransaction_throws_when_closed

        public void BeginTransaction_throws_when_closed()
        {
            var connection = new SqliteConnection();

            var ex = Assert.Throws<InvalidOperationException>(() => connection.BeginTransaction());

            Assert.Equal(Strings.FormatCallRequiresOpenConnection("BeginTransaction"), ex.Message);
        }
开发者ID:antiufo,项目名称:Microsoft.Data.Sqlite,代码行数:8,代码来源:SqliteConnectionTest.cs

示例9: CreateCommand_returns_command

        public void CreateCommand_returns_command()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:"))
            {
                connection.Open();

                using (var transaction = connection.BeginTransaction())
                {
                    var command = connection.CreateCommand();

                    Assert.NotNull(command);
                    Assert.Same(connection, command.Connection);
                    Assert.Same(transaction, command.Transaction);
                }
            }
        }
开发者ID:antiufo,项目名称:Microsoft.Data.Sqlite,代码行数:16,代码来源:SqliteConnectionTest.cs

示例10: ExecuteReader_throws_when_transaction_mismatched

        public void ExecuteReader_throws_when_transaction_mismatched()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:"))
            {
                var command = connection.CreateCommand();
                command.CommandText = "SELECT 1;";
                connection.Open();

                using (var otherConnection = new SqliteConnection("Data Source=:memory:"))
                {
                    otherConnection.Open();

                    using (var transction = otherConnection.BeginTransaction())
                    {
                        command.Transaction = transction;

                        var ex = Assert.Throws<InvalidOperationException>(() => command.ExecuteReader());

                        Assert.Equal(Strings.TransactionConnectionMismatch, ex.Message);
                    }
                }
            }
        }
开发者ID:antiufo,项目名称:Microsoft.Data.Sqlite,代码行数:23,代码来源:SqliteCommandTest.cs

示例11: IsolationLevel_is_infered_when_unspecified

        public void IsolationLevel_is_infered_when_unspecified()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:"))
            {
                connection.Open();
                connection.ExecuteNonQuery("PRAGMA read_uncommitted = 1;");

                using (var transaction = connection.BeginTransaction())
                {
                    Assert.Equal(IsolationLevel.ReadUncommitted, transaction.IsolationLevel);
                }
            }
        }
开发者ID:carloserodriguez2000,项目名称:Microsoft.Data.Sqlite,代码行数:13,代码来源:SqliteTransactionTest.cs

示例12: Dispose_can_be_called_more_than_once

        public void Dispose_can_be_called_more_than_once()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:"))
            {
                connection.Open();

                var transaction = connection.BeginTransaction();

                transaction.Dispose();
                transaction.Dispose();
            }
        }
开发者ID:carloserodriguez2000,项目名称:Microsoft.Data.Sqlite,代码行数:12,代码来源:SqliteTransactionTest.cs

示例13: Serializable_locks

 public void Serializable_locks()
 {
     using (var connectionA = new SqliteConnection("Data Source=testdb;Mode=Memory;Cache=Shared"))
     {
         connectionA.Open();
         using (var transactionA = connectionA.BeginTransaction(IsolationLevel.Serializable))
         {
             using (var connectionB = new SqliteConnection("Data Source=testdb;Mode=Memory;Cache=Shared"))
             {
                 connectionB.Open();
                 var ex = Assert.Throws<SqliteException>(() => new SqliteTransaction(connectionB, IsolationLevel.Serializable, 1));
                 Assert.Equal(SQLITE_LOCKED, ex.SqliteErrorCode);
             }
         }
     }
 }
开发者ID:carloserodriguez2000,项目名称:Microsoft.Data.Sqlite,代码行数:16,代码来源:SqliteTransactionTest.cs

示例14: Dispose_works

        public void Dispose_works()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:"))
            {
                connection.Open();
                CreateTestTable(connection);

                using (var transaction = connection.BeginTransaction())
                {
                    connection.ExecuteNonQuery("INSERT INTO TestTable VALUES (1);");

                    transaction.Dispose();

                    Assert.Null(connection.Transaction);
                    Assert.Null(transaction.Connection);
                }

                Assert.Equal(0L, connection.ExecuteScalar<long>("SELECT COUNT(*) FROM TestTable;"));
            }
        }
开发者ID:carloserodriguez2000,项目名称:Microsoft.Data.Sqlite,代码行数:20,代码来源:SqliteTransactionTest.cs

示例15: BeginTransaction_throws_when_parallel_transaction

        public void BeginTransaction_throws_when_parallel_transaction()
        {
            using (var connection = new SqliteConnection("Data Source=:memory:"))
            {
                connection.Open();

                using (connection.BeginTransaction())
                {
                    var ex = Assert.Throws<InvalidOperationException>(() => connection.BeginTransaction());

                    Assert.Equal(Strings.ParallelTransactionsNotSupported, ex.Message);
                }
            }
        }
开发者ID:antiufo,项目名称:Microsoft.Data.Sqlite,代码行数:14,代码来源:SqliteConnectionTest.cs


注:本文中的Microsoft.Data.Sqlite.SqliteConnection.BeginTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。