Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12963

SQL Server 2014 reseting isolation level

$
0
0

Hi,

Working with C# application accessing SQL Server 2012 and 2014 using ADO.NET.

There seem to be a change regarding isolation level reset when returning connection to pool.

Previous versions of SQL Server does not reset the isolation level on the connection (unfortunately) as claimed here (http://support.microsoft.com/?id=972915).

However it seems this has changed with SQL Server 2014.

If running the attached code it shows that the isolation level in fact is reset when running against a SQL Server 2014 instance but not 2012.

Can anyone on the SQL Server team confirm that this is an intended change that is here to stay? I have not seen any documentation on this so far in the behavior changes documented here: http://msdn.microsoft.com/en-us/library/ms143359.aspx

    class Program
    {
        static void Main(string[] args)
        {
            //AsyncTest.CallAsyncMethod_RunsInSeparateThread();
            TestIsolationLevelReset();
            Console.ReadLine();
        }

        public static void TestIsolationLevelReset()
        {
            var connectionString = @"Data Source=(local); Integrated Security=true; Initial Catalog=master;";
            var commandText = @"select cast (transaction_isolation_level as nvarchar) + ' - ' + CAST(@@spid as nvarchar) from sys.dm_exec_sessions where (session_id = @@SPID)";

            using (var conn = new SqlConnection(connectionString))
            {
                conn.Open();

                var cmd = new SqlCommand(commandText, conn);
                Console.WriteLine(cmd.ExecuteScalar());
            }

            using (var tran = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = IsolationLevel.Serializable }))
            using (var conn = new SqlConnection(connectionString))
            {
                conn.Open();

                var cmd = new SqlCommand(commandText, conn);
                Console.WriteLine(cmd.ExecuteScalar());

                tran.Complete();
            }

            using (var conn = new SqlConnection(connectionString))
            {
                conn.Open();

                var cmd = new SqlCommand(commandText, conn);
                Console.WriteLine(cmd.ExecuteScalar());
            }
        }
    }


Viewing all articles
Browse latest Browse all 12963

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>