开发者

SQL Server session

What is considered a session in sql server. I'm trying to use sp_getapplock and the documentation states:

Locks placed on a resource are associated with either the current transaction or the current session. Locks associated with the current transaction are released when the transaction commits or rolls back. Locks associated with the session are released when the session is logged out. When the server shu开发者_StackOverflow中文版ts down for any reason, all locks are released.

'Locks associated with the session are released when the session is logged out'.

I need to know what is considered a session. connecting using management studio is a session to the database; using asp.net to connect to sql server also creates a session.

What if I use ADO .net and connection pool, is every connection in the connection pool is considered to be a different session?


if I use ADO .net and connection pool, is every connection in the connection pool is considered to be a different session?

Sort of. Just about every time you open/close a new connection, that's a single session. However, one of the "features" of the connection pool is that it doesn't always open/close on command, and when it sees you're opening and closing a bunch of connections repeatedly it will use a single connection behind the scenes, which I believe results in a single session on sql server.


With connection pooling, notice that sp_reset_connection is called in between each reassignment of the reused connection. This SO Post covers the cleanup done by sp_reset_connection in detail.

Edit In the context of your question, sp_reset_connection "Frees acquired locks".


The @LockOwner of sp_getapplock refers to when it is released:

  • "Session": at session end
  • "Transaction": on COMMIT or ROLLBACK

Basically, a SPID in sys.sysprocesses is a "session"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜