Sadiq
Sadiq

Reputation: 838

Session vs Transaction

While I was reading about MARS I came across the following statement:

When MARS is enabled for use with SQL Server, each command object used adds a session to the connection.

I have heard of sessions before but not able to grasp the concept how it internally works and how a session is added to connection. I know what transaction is and isolation types and like. What's the difference between the two?

Upvotes: 3

Views: 2478

Answers (1)

usr
usr

Reputation: 171226

Sessions are a SQL Server concept to logically group an interaction of an application with the database. Temp tables are session scoped. When you call SqlConnection.Open you get a new session.

Here's my understanding of MARS internals:

SQL Server implements MARS by creating more than one session at a time per connection. Each concurrent command runs in its own session object. You can see this is the sessions DMV.

I don't think you need to know are care about this. This internal detail has no impact on the way you use the feature. In particular, transactions and isolation are not impacted (mentioning this because you mentioned those terms).

Upvotes: 3

Related Questions