问题描述
我使用的多层项目中,数据模型承载ADo.NET实体模型和数据访问层做验证。
I am using multiple layer project where the DataModel hosts the ADo.NET Entity model and DataAccess layer does the validation.
不过,每次我得到这样一个错误
However everytime I get a error like this
时,或者未在配置找到指定命名连接,并不意在与EntityClient提供者使用的,或不是有效的。
我试图连接字符串
<添加名称=SalesEntities connectionString="metadata=res://*/SalesEntities.csdl|res://*/SalesEntities.ssdl|res://*/SalesEntities.msl;provider=System.Data.SqlClient;provider连接字符串=安培; QUOT;数据源=;初始目录=凤凰;集成安全性= TRUE; MultipleActiveResultSets =真放; QUOT;的providerName =System.Data.EntityClient/>
和
<添加名称=SalesEntities connectionString="metadata=.\SalesEntities.csdl|.\SalesEntities.ssdl|.\SalesEntities.msl;provider=System.Data.SqlClient;provider连接字符串=安培; QUOT;数据源=;初始目录=凤凰;集成安全性= TRUE; MultipleActiveResultSets =真放; QUOT;的providerName =System.Data.EntityClient/>
<add name="SalesEntities" connectionString="metadata=.\SalesEntities.csdl|.\SalesEntities.ssdl|.\SalesEntities.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.;Initial Catalog=Phoenix;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
也尝试过其他的组合是指被叫项目目录,但没有运气的根目录。
also tried other combinations to refer the Root Directory of the Called project directory but no luck.
任何帮助是非常AP preciated。非常感谢一如既往:)。
Any help is highly appreciated. Many Thanks as always :).
推荐答案
您必须把这些连接字符串中的每个应用程序的app.config文件。如果您有生成的模型中,然后尝试消耗DAL在一个EXE同样的事情会发生一个DAL。该EXE不知道连接字符串。
You have to put those connection strings in each applications app.config file. If you have a DAL that you generated the model in, and then try to consume the DAL in an EXE the same thing will happen. The EXE does not know the connection string.
我发现最简单的就是把一个app.config上的每一个项目,只是复制从我在最初生成模型DAL连接字符串。然后每个将具有相同的连接字符串的副本。
The easiest thing I have found is to put an app.config on each project and just copy the connection string from the DAL I generated the models in originally. Then each will have a copy of that same connection string.
这篇关于ADO.NET实体连接字符串的多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!