Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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" 
like image 359
user1345260 Avatar asked May 06 '15 18:05

user1345260


2 Answers

In the DBContext file, remove

public RaficaDB()
: base("name=DefaultConnection"){}

to

public RaficaDB()
: base("DefaultConnection"){}

EF 4.3, EF 5 and EF 6 do not like the connection string being called name=xxxxx

Answer found here -> No connection string named 'MyApplicationEntities' could be found in the application config file

like image 98
dunwan Avatar answered Oct 11 '22 04:10

dunwan


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.

like image 23
Paolo Costa Avatar answered Oct 11 '22 03:10

Paolo Costa