在应用程序配置文件中找不到命名的连接字符串 [英] No connection string named could be found in the application config file
问题描述
然后我使用类文件创建一个实体模型,然后创建一个数据库上下文,然后创建存储库。我正在调用一个WebApi(它在一个单独的项目中,但是相同的解决方案)来访问存储库以获取数据。当我运行WebApi时,我收到错误,
{应用程序中没有找到名为DBEntities的连接字符串配置文件。}
但在我的DAL中,我有一个webConfig,并且有以下条目,所以我不太确定出了什么问题,
add name =DBEntitiesconnectionString =metadata = res://*/Models.DBModel。 csdl | res://*/Models.DBModel.ssdl | res://*/Models.DBModel.msl; provider = System.Data.SqlClient; provider connection string =& quot; data source = MY-PC; initial catalog = DB; integrated security = True; multipleactiveresultsets = True; application name = EntityFramework& quot; providerName =System.Data.EntityClient
你说在我的DAL内,我有一个webConfig。我想连接字符串在引用的类库的配置文件中,但不在您的入口项目中的主配置文件(web api项目,我想看看标签)。
如果是这样,只需复制条目项目配置文件中的连接字符串。
I'm using EF and generated .EDMX from it but then I only wanted it to be used for automated generation of Class Files.
I then used the Class Files to create a Entity Model and then created a DB Context and then Repository. I'm calling a WebApi (which is in a separate project but same solution) to access the repository to GET data. While I run the WebApi, I'm getting the error,
{"No connection string named 'DBEntities' could be found in the application config file."}
But within my DAL, I have a webConfig and that has the following entry so I'm not quite sure what has gone wrong,
add name="DBEntities" connectionString="metadata=res://*/Models.DBModel.csdl|res://*/Models.DBModel.ssdl|res://*/Models.DBModel.msl;provider=System.Data.SqlClient;provider connection string="data source=MY-PC;initial catalog=DB;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient"
You say "within my DAL, I have a webConfig". I guess the connection string is in the configuration file of a referenced class library, but not in the main configuration file you have in your entry project (a web api project, I guess looking at the tags).
If so, just copy the connection string in the entry project configuration file.
这篇关于在应用程序配置文件中找不到命名的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!