Search code examples
c#entity-frameworkasp.net-web-api

No connection string named could be found in the application config file


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" 

Solution

  • 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.