Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable MultipleActiveResultSets

Tags:

c#

sql

asp.net

I have the following connection string in my code:

SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["RaiseFantasyLeagueConnectionString"].ConnectionString);

My webconfig for this looks like this:

    <connectionStrings>
<add name="RaiseFantasyLeagueConnectionString" connectionString="Data Source=MATT-PC\SQLEXPRESS;Initial Catalog=Raise;Integrated Security=True" providerName="System.Data.SqlClient"/>

Can somebody tell me where I can enable MultipleActiveResultSets for my connection?

like image 208
JackofAll Avatar asked Mar 31 '13 18:03

JackofAll


People also ask

What is the use of MultipleActiveResultSets?

Multiple Active Result Sets (MARS) is a feature that allows the execution of multiple batches on a single connection. In previous versions, only one batch could be executed at a time against a single connection. Executing multiple batches with MARS does not imply simultaneous execution of operations.

What is Mars with respect to SQL Server?

MARS enables the interleaved execution of multiple requests within a single connection. That is, it allows a batch to run, and within its execution, it allows other requests to execute.

What is connection string app?

App and Application Name are simply a way for somebody debugging SQL Server to know which client is connecting to it. If you had a SQL Server that has several apps that used it, it might be hard to know which one was sending which statements. If each app used a different Application Name it would be very clear.


2 Answers

It is really simple, just add

MultipleActiveResultSets=true;

so change, in your web.config, the connection string in this way:

connectionString="Data Source=MATT-PC\SQLEXPRESS;" + 
                 "Initial Catalog=Raise;Integrated Security=True;" + 
                 "MultipleActiveResultSets=true;" 
like image 89
Steve Avatar answered Sep 19 '22 17:09

Steve


Try this code

<connectionStrings>
<add name="RaiseFantasyLeagueConnectionString" connectionString="Data Source=MATT-PC\SQLEXPRESS;Initial Catalog=Raise;Integrated Security=True ;MultipleActiveResultSets=True;" providerName="System.Data.SqlClient";/>

Must refer this Msdn article

like image 26
Ramesh Rajendran Avatar answered Sep 21 '22 17:09

Ramesh Rajendran