我正在尝试将我的Entity Framework映射连接到托管站点上的Sql服务器。
可以在以下堆栈跟踪中找到此问题:
[MetadataException: Unable to load the specified metadata resource.]
System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.LoadResources(String assemblyName, String resourceName, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver) +387
System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource..ctor(String originalPath, String assemblyName, String resourceName, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver) +72
System.Data.Metadata.Edm.MetadataArtifactLoaderCompositeResource.CreateResourceLoader(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver) +222
System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver) +74
System.Data.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection`1 uriRegistry) +68
我假设我的连接字符串未正确设置,因为我需要在运行时动态生成此字符串。 String如下所示:
<add name="Model1Container-providerConnectionString"
connectionString="data source=something.sqlserver.sequelizer.com;
User ID=**;
Password=**;
Initial Catalog=dbd5d3955e11834e1088929f9d005af0a8;
user instance=True;multipleactiveresultsets=True;App=EntityFramework" />
然后在运行时,字符串构造如下:
public static string GetConnectionString()
{
string baseConnectionString = ConfigurationManager.ConnectionStrings["Model1Container-providerConnectionString"].ConnectionString;
EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
entityBuilder.Provider = "System.Data.SqlClient";
entityBuilder.ProviderConnectionString = baseConnectionString;
entityBuilder.Metadata = @"res://*/DBModel.csdl|res://*/DBModel.ssdl|res://*/DBModel.msl";
return entityBuilder.ToString();
}
}
现在已经在这个问题上工作了几天,非常感谢社区在寻找工作解决方案方面的专业知识。