SqlConnection vs Sql Session. Do their lifetimes coincide?

…衆ロ難τιáo~ 提交于 2019-12-10 02:11:53

问题


I want to apply some sql-session level settings for certain processes in my c# app.

For instance, I want to set DEADLOCK_PRIORITY for some background processes to LOW.

The questions are:

  1. If I open a new sql connection, does that start a new sql-session?

  2. Will the sql-session live until the connection is closed? If I apply my settings right after the SqlConnection is opened, will they be valid for all queries executed in context of that same SqlConnection?

  3. What about connection pooling? Is this possible that my SET DEADLOCK_PRIORITY LOW setting will be reused by other processes in my system (which I don't want to) because the SqlConnection is not actually closed ( asp.net connection pooling decides to reuse it).

Thank you!


回答1:


ADO.NET executes sp_reset_connection when you take a SqlConnection from the pool (after having closed it so that it gets returned to the pool). According to What does "exec sp_reset_connection" mean in Sql Server Profiler? all SET options are being reset. That would include DEADLOCK_PRIORITY.

I would still suggest that you write a tiny test program to confirm this. ADO.NET session pooling is not perfect, for example it does not reset the ISOLATION LEVEL and does not rollback transactions when closing.



来源:https://stackoverflow.com/questions/16613242/sqlconnection-vs-sql-session-do-their-lifetimes-coincide

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