14

I have created a class library project, which contains the entity framework object, who will be responsible for common data access layer for my multiple project. After adding the generated dll file to my domain project, and using the entity object from the class library project, I am facing with the following issue.

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

I have set the Metadata Artifact processing property of edmx to Embed in Output Assembly.

App.Config markup

  <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="ABC" connectionString="metadata=res://*/Entity.ABC.csdl|res://*/Entity.ABC.ssdl|res://*/Entity.ABC.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\ABC.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>
</configuration>

And Entities code are as follow

public ABC_IntegrationEntities()
            : base("name=ABC")
        {
        }

One more thing: I am accessing database from datadirectiory "App_Data".

I am referencing the blog from dotnetcurry.com.

peterh
  • 11,875
  • 18
  • 85
  • 108
Nik's
  • 191
  • 2
  • 2
  • 12
  • To answer this question we would need to see your app.config file contents as well as the constructor for your Context class (Object or Db). – Rob Epstein Aug 20 '14 at 13:24
  • Hi rob i have updated the my question please have a look.Thanks – Nik's Aug 20 '14 at 13:35
  • The connectionString in the config file that currently has the name "Gumu_IntegrationEntities" needs to have the name "ABC" instead. – Rob Epstein Aug 20 '14 at 13:36

4 Answers4

9

Based on the link you gave, probably you miss this part.

Now you can either create your own .config file in this project and add the connectionstring entry of your model or simply copy the App.config file that you created in the MyEntityModel project, in your Console App project. We will adopt the simpler way. Right click the project > Add Existing Item > Go to the MyEntityModel project and add the App.config file.

Explanation:

When you create a library and the library is referenced from another project, EF will read the config that is relative to start up project. You can do one of the following.

  • Copy the config from library's config (copy the file and paste it to start up project)
  • Create a new config but copy the connection string information and other EF related section
  • Add existing config by add existing item and add it as link to library's config
Yuliam Chandra
  • 14,494
  • 12
  • 52
  • 67
  • Hi Yuliam i gone through the adding existing app.config into the domain project where i am accessing the edmx from dll,but getting the same error. – Nik's Aug 20 '14 at 13:38
  • @Nik's, Is **domain project** the startup project in the solution? And does startup project have the config that has connection string information? – Yuliam Chandra Aug 20 '14 at 13:41
  • No we are not added any connection string into domain project ,yes its a startup project. – Nik's Aug 20 '14 at 13:43
  • @Nik's, then you need to add the config file in the domain project (start up project). Then provide the connection string information and EF related section – Yuliam Chandra Aug 20 '14 at 13:45
  • thanks for reply actually i have a database file in data directiory app_data inside the class library project.i am not connecting to any beta server. – Nik's Aug 20 '14 at 13:52
  • 1
    @Nik's, you still need to have a connection string that refers to the local database file, either in the start up project, or programmatically mention it in the dbcontext connection, but because you explicitly mentioned this `base("name=ABC")`, that means EF expects a connection string name in start up project config file – Yuliam Chandra Aug 20 '14 at 13:57
1

I have been working on creating class library that implements all EF (Entity Framework) functionality and followed the process outlined in http://www.dotnetcurry.com/showarticle.aspx?ID=617 but still it was giving errors.

The problem was version mismatch between EF framework and .Net framework. I was using .Net framework 5.0 but EF version was 6.0. After updating latest version of .Net framework, everything started working good. Always ensure EF and Dll version + EF and test project versions are always same.

I also downloaded and installed EFTools6.1.3ForVS2013, if that helps anyone. Other thing to remember is you have to install Entity Framework from Nuget in all projects that references EF Dll and copy connectionstring from Dll config file in test project's config file.

Hope this helps someone !!! Thanks,

Anki
  • 11
  • 2
1

Copy your SQL connection string from library project's config file and paste it into the main project's config file which is your startup project. Which will resolve your issue.

Also, copy DbProviderFactories from library project to the main project's config file.

Nikhil Dinesh
  • 3,359
  • 2
  • 38
  • 41
0

Change the name of entity connection string you are using in the constructor of your context class:

public ABC_IntegrationEntities()
                : base("name=Gumu_IntegrationEntities")
            {
            }

Make sure you have your application configuration file added to the assembly where you execute your code from, i.e app.config of you PE of web.config of your website

Andrew
  • 3,648
  • 1
  • 15
  • 29
  • It's probably easier to change the config file than it is to recompile the data layer. – Rob Epstein Aug 20 '14 at 13:37
  • Sorry Andrew my connection string Name is ABC,wrogly posted. – Nik's Aug 20 '14 at 13:39
  • ok, then make sure you refer to correct app.config file(not the one where your model is, but the one of an assembly that executes the code). – Andrew Aug 20 '14 at 13:41
  • and based on 'Entity.ABC.csdl', I assume your model 'ABC' is located in 'Entity' subfolder of your project – Andrew Aug 20 '14 at 13:42
  • Yes Andrew we have the proper csdl located into the class library project and we are accessing the app.config file for configuration of edmx. thanks – Nik's Aug 20 '14 at 13:47
  • I'd inspect `ConfigurationManager.ConnectionStrings` object for entries, if your connection string is not there, than you've updated wrong `.config` file. – Andrew Aug 20 '14 at 13:51
  • @Andre i tried with the dyanamic fetching of connection string from this classes.even i have added a app.cofig file into my domain project still getting the same error.is there any issue with Build Action property? – Nik's Aug 20 '14 at 13:56
  • do you have release.config and debug.config in your application start project? – Andrew Aug 20 '14 at 13:57
  • Yes and every section are commented. – Nik's Aug 20 '14 at 14:04
  • make sure that the version of config file you've updated corresponds to the build you are executing. – Andrew Aug 20 '14 at 14:05