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

前端 未结 9 1158
时光取名叫无心
时光取名叫无心 2020-12-29 06:54

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 Enti

相关标签:
9条回答
  • 2020-12-29 07:03

    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.

    0 讨论(0)
  • 2020-12-29 07:04

    If none of the above fixes the issue, then probably you are doing the mistake I did, here was my case: I have multiple projects in my solution and the Startup project was different than the one having the entity framework, switching project from the package manager console seems like a buggy thing especially in entity framework commands, so here what I did:

    1. Set your webapi(Or the project has the entity framework) as a startup project.
    2. Rebuild the solution and try again.
    3. Run the entity framework command again.

    If the above doesn't work then try to close the solution and try from Step 2, this should fix it.

    0 讨论(0)
  • 2020-12-29 07:06

    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

    0 讨论(0)
  • 2020-12-29 07:13

    I found that this worked:

    1) Check if you have several "App.config" files. 2) Check if has a wrong name than the connection string it has to use. 3) Save the project and run the program

    It should work now.

    0 讨论(0)
  • 2020-12-29 07:17

    Setting the project as Startup project worked for me

    0 讨论(0)
  • 2020-12-29 07:20

    Insert following section in the configuration section of the .config file of the same project where your .edmx file is under.

    You may also create different connection string for different environment in the .config file of the main project and pass any of the connection string as parameter of the constructor of the DBContext.

    <connectionStrings>
      
    <add name="DBEntities" connectionString="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" />
    
    </connectionStrings>

    0 讨论(0)
提交回复
热议问题