views:

315

answers:

2

The only SET parameter that I have found specific guidance for is SET TRANSACTION ISOLATION LEVEL:

If you issue SET TRANSACTION ISOLATION LEVEL in a stored procedure or trigger, when the object returns control the isolation level is reset to the level in effect when the object was invoked. For example, if you set REPEATABLE READ in a batch, and the batch then calls a stored procedure that sets the isolation level to SERIALIZABLE, the isolation level setting reverts to REPEATABLE READ when the stored procedure returns control to the batch.

What about other SET parameters, like SET XACT_ABORT or SET DEADLOCK_PRIORITY? If you set those during a stored procedure (or a batch submitted from C#), will they go back to their previous values the next time the connection gets used?

A: 

I believe Transaction Isolation Level remains set for the rest of the current session. That means that even after such a stored proc returns, if client cide calls another stored proc on the same connection (in the same session) that second proc will be executed under the same isolation level.

Charles Bretana
That's totally the opposite of what the documentation says.
Eric Z Beard
@Eric, yes, I read only the body of question, missed the reference to .Net in the title, ... From SQL Books Online - "Only one of the isolation level options can be set at a time, and it remains set for that connection until it is explicitly changed." sp_reset_connection is client-side behavior...
Charles Bretana
+3  A: 

By default (that is, unless you include "Connection Reset=false" in the connection string), .NET resets the connection with the sp_reset_connection stored procedure before reusing it; among other things it undoes any SET commands that have been issued since the connection was opened.

See this article for more details.

technophile
I did not know that. Good stuff. Thanks!
Booji Boy
If you do any SQL tracing in ASP.NET applications it sticks out like a sore thumb, you'll see calls to sp_reset_connection all over the place. :)
technophile
That article doesn't render correctly in Firefox. You have to select all to see the text. But it's good info, thanks!
Eric Z Beard