Asp.net-mvc – SQL Azure + Getting an error ‘There is already an open DataReader associated with this Command..’, even after setting ‘MultipleActiveResultSets=True’

asp.net-mvcazureazure-sql-database

We are facing some issues with the deployed version of our application on cloud.

Our application is an ASP.NET MVC 3 project with ADO .NET Entity Framework.

According to the msdn blogs, we need to add the parameter ‘MultipleActiveResultSets=True’ (for Entity Framework with SQL azure) in our database connection string which we have rightly done.

We get the following exception while executing a database query from our application: ‘’There is already an open DataReader associated with this Command which must be closed first.”,
which I guess is very much related to the ‘MultipleActiveResultSets=True’ property.

The application works fine on the local environment with our locally deployed database as well as using the SQL azure database (on local environment).

But when we deploy our application of cloud we get the above mentioned error. It seems that ‘MultipleActiveResultSets=True’ property is not being read from the connection string.

The connection string that I am using is as follows:

    <connectionStrings>
        <add name="#DBInstanceName#" connectionString="Data Source=tcp:#server#.database.windows.net,1433;Initial Catalog=#DBName#;User ID=”UserName#@#server#;Password=”#password#”;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>
    </connectionStrings>

I am able to connect to SQL Azure database using the above connection string from the locally deployed application without any exceptions. But the same application when deployed on cloud using the same connection string gives me the above mentioned error.

Can you please help us fixing the same?

Best Answer

I've just got the same issue. I has tried setting "MultipleActiveResultSets=True" in Web.config connection - no results. Finally I've resolved issue by manually editing Connection string directly at Azure Dashboard for the web site - in "Configure" tab there is "Connection strings" settings where you should manually add the "MultipleActiveResultSets=True;" string. After doing that I've got MARS worked finally.

Related Topic