c# – 如何在带有sequelizer附加组件的appharbor上运行的应用程序中启用MultipleActiveResultSets?
作者:互联网
在本地开发时,我有一个设置为MultipleActiveResultSets的连接字符串设置为TRUE.但是,当我部署我的应用程序并注入sequelizer connectionString时,会遗漏MultipleActiveResultSets.反正有没有启用MultipleActiveResultSets或以其他方式更新连接字符串?
我顺便使用Entity Framework 4.1.
解决方法:
更新:现在可以使用Sequelizer管理面板为注入的连接字符串启用多个活动结果集(MARS).这是推荐的方法,因为不再需要修改web.config,这会导致在启动期间重新加载AppDomain
您可以从注入应用程序web.config的URI构造connectionstring.这个过程描述为here,但我也包括下面的代码片段:
var uriString = ConfigurationManager.AppSettings["SQLSERVER_URI"];
var uri = new Uri(uriString);
var connectionString = new SqlConnectionStringBuilder
{
DataSource = uri.Host,
InitialCatalog = uri.AbsolutePath.Trim('/'),
UserID = uri.UserInfo.Split(':').First(),
Password = uri.UserInfo.Split(':').Last(),
MultipleActiveResultSets = true,
}.ConnectionString;
请注意MultipleActiveResultSets = true.
如果您还需要构建非Code-First连接字符串,则需要使用EntityConnectionStringBuilder,例如:
var builder = new EntityConnectionStringBuilder();
builder.ProviderConnectionString = connectionString;
builder.Metadata = "somemetadata";
builder.Provider = "System.Data.SqlClient";
(也是answered on the AppHarbor support forum)
标签:c,asp-net-mvc,entity-framework,entity-framework-4-1,appharbor 来源: https://codeday.me/bug/20190613/1234811.html