Get current .net TransactionScope IsolationLevel

China☆狼群 提交于 2019-12-02 09:57:10

Can you run a SQL query to check the isolation level:

SELECT CASE transaction_isolation_level 
WHEN 0 THEN 'Unspecified' 
WHEN 1 THEN 'ReadUncomitted' 
WHEN 2 THEN 'Readcomitted' 
WHEN 3 THEN 'Repeatable' 
WHEN 4 THEN 'Serializable' 
WHEN 5 THEN 'Snapshot' END AS IsolationLevel 
FROM sys.dm_exec_sessions 
where session_id = @@SPID

EDIT

Based on the comments below, there's also a way to get the isolation level from the code. This could be something like that:

using (TransactionScope scope = new TransactionScope())
{
    using (SqlConnection connection1 = new SqlConnection("Data Source=localhost;Integrated Security=True"))
    {
        Transaction trans = Transaction.Current;
        System.Transactions.IsolationLevel level = trans.IsolationLevel;
    }
}

You can get the current transaction by calling Transaction.Current.

Source: Implementing an Implicit Transaction using Transaction Scope

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!