Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 shuts 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?

like image 817
diana Avatar asked Sep 22 '11 13:09

diana


People also ask

What is a SQL Server session?

A SQL session is an occurrence of a user interacting with a relational database through the use of SQL commands. When a user initially connects to the database, a session is established.

How many sessions is SQL Server running?

In SQL Server Management Studio, right click on Server, choose "Activity Monitor" from context menu -or- use keyboard shortcut Ctrl + Alt + A .

What is a session in database?

A session represents the connection between an application and the relational database that stores its persistent objects. TopLink provides several different session objects that all implement the same Session interface.

What is the difference between session and connection?

Literally : Connection is Physical Communication Channel and Session is a state of information exchange. A Connection may have multiple sessions . The connection is the physical communication channel between SQL Server and the application: the TCP socket, the named pipe, the shared memory region.


1 Answers

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.

like image 59
Joel Coehoorn Avatar answered Sep 20 '22 13:09

Joel Coehoorn