• 查询并验证 TransactionScope 隔离级别


    void Main()
    {
        this.ExecuteQuery<string>(@"SELECT  CASE transaction_isolation_level
                                          WHEN 0 THEN 'Unspecified'
                                          WHEN 1 THEN 'ReadUncommitted'
                                          WHEN 2 THEN 'ReadCommitted'
                                          WHEN 3 THEN 'Repeatable'
                                          WHEN 4 THEN 'Serializable'
                                          WHEN 5 THEN 'Snapshot'
                                        END AS TRANSACTION_ISOLATION_LEVEL
                                FROM    sys.dm_exec_sessions
                                WHERE   session_id = @@SPID;", new object[] { }).Dump();
    
        using (var tran = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 0, 120)))
        {
            this.ExecuteQuery<string>(@"SELECT  CASE transaction_isolation_level
                                          WHEN 0 THEN 'Unspecified'
                                          WHEN 1 THEN 'ReadUncommitted'
                                          WHEN 2 THEN 'ReadCommitted'
                                          WHEN 3 THEN 'Repeatable'
                                          WHEN 4 THEN 'Serializable'
                                          WHEN 5 THEN 'Snapshot'
                                        END AS TRANSACTION_ISOLATION_LEVEL
                                FROM    sys.dm_exec_sessions
                                WHERE   session_id = @@SPID;", new object[] { }).Dump();
        }
        
        var transactionOptions = new System.Transactions.TransactionOptions();
        transactionOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
        using (var transactionScope = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOptions))
        {
            this.ExecuteQuery<string>(@"SELECT  CASE transaction_isolation_level
                                          WHEN 0 THEN 'Unspecified'
                                          WHEN 1 THEN 'ReadUncommitted'
                                          WHEN 2 THEN 'ReadCommitted'
                                          WHEN 3 THEN 'Repeatable'
                                          WHEN 4 THEN 'Serializable'
                                          WHEN 5 THEN 'Snapshot'
                                        END AS TRANSACTION_ISOLATION_LEVEL
                                FROM    sys.dm_exec_sessions
                                WHERE   session_id = @@SPID;", new object[] { }).Dump();
        }
    }
    
    // Define other methods and classes here
  • 相关阅读:
    UVA 10617 Again Palindrome
    UVA 10154 Weights and Measures
    UVA 10201 Adventures in Moving Part IV
    UVA 10313 Pay the Price
    UVA 10271 Chopsticks
    Restore DB後設置指引 for maximo
    每行SQL語句加go換行
    种服务器角色所拥有的权限
    Framework X support IPV6?
    模擬DeadLock
  • 原文地址:https://www.cnblogs.com/nanfei/p/12964642.html
Copyright © 2020-2023  润新知