This is my first stackoverflow question, so bear with me.
In my local project, I am using ASP.NET MVC 3 and Entity Framework 4.3 with SQL Express.
in my connection string, I set MARS to true;
but when I deploy my project to Appharbor, Appharbor introduces its own connection string,
where MARS is not specified in the connection string. So I get the following:
There is already an open DataReader associated with this Command which must be closed first.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.
So far, the best solution I've seen about this is: http://support.appharbor.com/kb/add-ons/using-sequelizer
where they have this code:
var configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
var connectionString = configuration.ConnectionStrings.ConnectionStrings["ConnectionstringAlias"].ConnectionString;
if (!connectionString.Contains("MultipleActiveResultSets=True;"))
{
connectionString += "MultipleActiveResultSets=True;";
}
configuration.ConnectionStrings.ConnectionStrings["ConnectionstringAlias"].ConnectionString = connectionString;
configuration.Save();
I can’t figure out where to place this, tried to put it in the global under
Aplication_Start () Method
But this gives me this error:
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 50:
Line 51: var configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
Line 52: var connectionString = configuration.ConnectionStrings.ConnectionStrings["ConnectionstringAlias"].ConnectionString;
Line 53: if (!connectionString.Contains("MultipleActiveResultSets=True;"))
Line 54: {
Source File: C:\Users\William\Documents\Visual Studio 2010\Projects\xxx\xxx\Global.asax.cs Line: 52
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Educationexpander.MvcApplication.Application_Start() in C:\Users\William\Documents\Visual Studio 2010\Projects\xxx\xxx\Global.asax.cs:52
Is there anyone with a solution to this problem?