ADO.NET Entity Framework “Unable to load the specified metadata resource”解决方法
Posted on 2011-04-04 23:12 宽田 阅读(890) 评论(0) 编辑 收藏 举报当我使用下边代码打开Entity时。程序报 “Unable to load the specified metadata resource”错。
string con = "name = NorthwindEntities";
using (EntityConnection econn = new EntityConnection(esb.ConnectionString))
{
econn.Open();
}
using (EntityConnection econn = new EntityConnection(esb.ConnectionString))
{
econn.Open();
}
错误是因为Web.Config连接节点中connectionString引起。请看系统的Web.Config连接节点。
<configuration>
<connectionStrings>
<add name="NorthwindEntities"
connectionString="metadata=res://*/NothWind.csdl|res://*/NothWind.ssdl|res://*/NothWind.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.;Initial Catalog=Northwind;User ID=sa;Password=123;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
<connectionStrings>
<add name="NorthwindEntities"
connectionString="metadata=res://*/NothWind.csdl|res://*/NothWind.ssdl|res://*/NothWind.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.;Initial Catalog=Northwind;User ID=sa;Password=123;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
将Metadata中"*"换成.edmx所在程序集的名称即可。如下。
<configuration>
<connectionStrings>
<add name="NorthwindEntities"
connectionString="metadata=res://EFModel/NothWind.csdl|res://EFModel/NothWind.ssdl|res://EFModel/NothWind.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.;Initial Catalog=Northwind;User ID=sa;Password=123;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
<connectionStrings>
<add name="NorthwindEntities"
connectionString="metadata=res://EFModel/NothWind.csdl|res://EFModel/NothWind.ssdl|res://EFModel/NothWind.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.;Initial Catalog=Northwind;User ID=sa;Password=123;MultipleActiveResultSets=True""
providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>