我被卡住了。我花了将近一天的时间来解决,但无济于事。实体框架中的connectionString
问题:使用实体框架连接到生产数据库。
我连接开发很好。
<add name="DefaultConnectionString" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=MONDO;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="MONDOEntities" connectionString="metadata=res://*;provider=System.Data.SqlClient;provider connection string="Data Source=.\SQLEXPRESS;Initial Catalog=MONDO;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
移动到生产中,我使用(从生产web.config文件)现有的 “DefaultConnectionString” 参数(ID和密码)来编辑MONDOEntities的connectionString。 (我可以这样做吗?)另外,我将MONDOEntities中的元数据扩展为包含.csdl,.ssdl,.msl,并在前缀(猜测,我可以这样做吗?)MONDO。粗体部分从dev web.config更改为生产web.config。 *请注意,下面的connectionStrings不是由Visual Studio创建的,我只是自己改变了一些信息,试图让它在生产环境中工作。
<add connectionString="Data Source=MPOC\SQLEXPRESS;Database=Mondo;User ID=xxx;Password=xxxxx;" name="DefaultConnectionString" />
<add name="MONDOEntities" connectionString="metadata=res://*/MONDO.csdl|res://*/MONDO.ssdl|res://*/MONDO.msl;provider=System.Data.SqlClient;provider connection string="Data Source=MPOC\SQLEXPRESS;persist security info=True;Database=Mondo;User ID=xxx;Password=xxxxx;MultipleActiveResultSets=Tru e;App=EntityFramework"" providerName="System.Data.EntityClient" />
我得到的错误消息是: 无法加载指定的元数据资源。
Line 62: /// Initializes a new MONDOEntities object using the connection string found in the 'MONDOEntities' section of the application configuration file.
Line 63: /// </summary>
Line 64: public MONDOEntities() :
问题:可以,我只是手工修改的ConnectionStrings或是否需要通过一个汇编程序运行?这是一个网站项目,因此它在我上传到产品后第一次编译。它不会在我的本地开发计算机上进行预编译。我猜,底线,我如何为生产中的数据库的实体连接设置适当的connectionString?
我在一个项目,我需要学习一个现有的网站。我正在进行第一次错误修复并学习了ado.net,我创建了一个实体数据模型并对代码进行了一些更改。一切工作顺利进行。
我将文件移动到生产,然后我得到这个错误:
"The specified default EntityContainer name 'MONDOEntities' could not be found in the mapping and metadata information.
Parameter name: defaultContainerName"
我GOOGLE了此错误信息,并根据一些发现,我扩大如下图所示我的“元数据”。这是更黑暗中拍摄的我:
ORIGINAL(在web.config中自动生成的,当我创建实体数据模型):
connectionString="metadata=res://*
NEW(我编辑/添加此):
connectionString="metadata=res://*/MONDO.csdl|res://*/MONDO.ssdl|res://*/MONDO.msl;
这似乎让过去的第一个错误,我得到一个新的错误信息(如OP发布):
Unable to load the specified metadata resource.
Line 62: /// Initializes a new MONDOEntities object using the connection string found in the 'MONDOEntities' section of the application configuration file.
Line 63: /// </summary>
Line 64: public MONDOEntities() :
我认为我的元数据信息存在问题。但是,假设原始的自动生成的connectString只包含“metadata = res:// *”,我真的不知道如何去纠正这个问题。实际上,我甚至不确定这是问题的根源。
底线,我的实体模型在dev中平滑工作,但没有连接到生产中。任何想法都赞赏......谢谢。
下面是我的研究到目前为止:oops,我会在下面发表,不在这里的评论部分...没有格式在这里......; -x – nanonerd 2012-07-17 23:06:21