What is the difference between a connection and a session and how they are related?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
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
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
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.