这是我在stackoverflow的第一个问题,请耐心等待。
在我的本地项目中,我使用ASP.NET MVC 3和Entity Framework 4.3和SQL Express。
在我的连接字符串中,我将MARS设置为true;
但是当我将我的项目部署到Appharbor时,Appharbor会注入自己的连接字符串,
其中MARS未在connectionstring中设置。所以我明白了:
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.
到目前为止,我已经看到了最好的解决方案:http://support.appharbor.com/kb/add-ons/using-sequelizer
他们有这个代码:
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();
我无法弄清楚将它置于何处,试图将其置于全球
之下Aplication_Start()方法
但是这给了我这个错误:
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
有没有人解决这个问题?
答案 0 :(得分:3)
更新:现在可以使用Sequelizer管理面板为注入的连接字符串启用多个活动结果集(MARS)。这是推荐的方法,因为不再需要修改web.config
,这会导致在启动期间重新加载AppDomain
答案在上面的评论中,这只是形式化。
您需要使用正确的ConnectionstringAlias
(感谢@ chris-sainty),您必须在应用程序设置中启用文件系统写入,以便将更新的配置写入磁盘。