I read this topics:
SQL Server 2014 reseting isolation level
How do I unset/reset a transaction isolation level for SQL Server?
What does sp_reset_connection do?
And so many posts and blogs...
I have some questions about this topics:
I couldn't find a reliable reference from Microsoft sites that explain reset
ISOLATION LEVEL
in SQL Server 2014 andsp_reset_connection
. How can I be sure that this happened andISOLATION LEVEL
reset to it's default value.Does it correct that changing
ISOLATION LEVEL
in stored procedures, just have scope in the scope of the stored procedure? Doesn't it affect connection?
Thanks
select transaction_isolation_level from sys.dm_exec_requests where session_id = @@SPID
to get the current isolation level, change it, and then do the sp_reset_connection thing – FissureTransactionScope
. Consider using a separate, slightly different connection string in order to get a different connection pool for this query. Alternatively, you can manually set an isolation level per table that you query usingFromSqlRaw
. Also what happens if you open an explicit database transaction withusing var tran = dbContext.Database.BeginTransaction();
– Terrifysp_reset_connection
does not reset the isolation level by design with or withoutTrasnactionScope
. Regarding #2, allSET
commands executed in a proc are reverted when the proc exits, includingSET TRANSACTION ISOLATION LEVEL.
. – RemonstranceTransactionScope
callssp_reset_connection
without keeping the transaction. A new field in TDS was added for this, but because older clients hadn't been updated, nothing was changed in the end. – TerrifyRESETCONNECTIONSKIPTRAN
bit flag was added forTransactionScope
. – Terrifysp_executesql
RPC calls to do that, so that counts as a separate scope, whereas without parameters most clients just send an Ad-Hoc Batch, which is not. – Terrifysp_reset_connection
does not get executed directly. The client API sets a flag in the TDS request when the first query on a reused pooled connection is executed, This causes the database engine to executesp_reset_connection
internally to restore the session to the state of a new connection, sans isolation level. – RemonstranceTransactionScope
used the normal reset. The reset of the isolation level and transaction status meant thatTransactionScope
stopped working. MS restored the old behaviour, so rolling back the original fix. – Terrify