What is the difference between a connection and a session?

The connection is the physical communication channel between SQL Server and the application: the TCP socket, the named pipe, the shared memory region. The session in SQL Server corresponds to the Wikipedia definition of a session: a semi-permanent container of state for an information exchange. In other words the sessions stores settings like cache of your login information, current transaction isolation level, session level SET values etc etc.

Normally there is one session on each connection, but there could be multiple session on a single connection (Multiple Active Result Sets, MARS) and there are sessions that have no connection (SSB activated procedures, system sessions). There are also connections w/o sessions, namely connections used for non-TDS purposes, like database mirroring sys.dm_db_mirroring_connections or Service Broker connections sys.dm_broker_connections.


  • Connection represents connection to the server over a network or locally through shared memory .

  • A session represents a user process within SQL Server.

  • A connection may be linked with zero or more then one session.


You can query the sys.dm_exec_sessions dynamic management views to learn information about successful and unsuccessful logins when common criteria compliance is enabled on a SQL Server 2012 instance.

The sys.dm_exec_connections dynamic management view provides information about connections established to the Database Engine instance. You can't query this dynamic management view for information about successful and unsuccessful logins when common criteria compliance is enabled on a SQL Server 2012 instance.

Tags:

Sql Server