none
EntityConnection error: The specified named connection is either not found in the configuration...

    Question

  •  

    I am getting the following error when attempting to connect to the EDM:

    "The specified named connection is either not found in the configuration, not intended to be used with the EntityClient Provider, not valid."

     

    The code I am using to connect to the EDM is below; the error is thrown when attempting to create the EntityConnection (in bold):

                using (EntityConnection connection =
                      new EntityConnection("name=AdventureWorksEntities"))
               
    {
                    AdventureWorksEntities context = new AdventureWorksEntities(connection);
                    context.AddObject("Customer", customer);
                    context.SaveChanges();
                }

     

     

    This code is executing from a different project in my solution than the project where the EDM is.  The same App.Config file (shown below)  containing the connection string (which was generated by the EDM wizard) exists in both projects in the solution.

     

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <connectionStrings>
        <add name="AdventureWorksEntities" connectionString="metadata=.\AdventureWorksModel.csdl|.\AdventureWorksModel.ssdl|.\AdventureWorksModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=terryc01;Initial Catalog=AdventureWorks;Integrated Security=True&quot;" providerName="System.Data.EntityClient" />
      </connectionStrings>
    </configuration>

     

    Any ideas?

    Saturday, September 08, 2007 5:27 PM

Answers

  • My only guess is the app.config is not in the binary directory where the exe is. Please do the following:

    1.    Visually verify that the app.config with the expected content is in the directory where the exe is compiled. (Existence in the project root directory is not enough.)

    2.    Use System.Configuration.ConfigurationManager from within your app to examine the content of the app.config your exe is using.

     

    I’m also looking at the content of the connection string, and I can say that it may not work in a multi project environment (unless you’ve duplicated the EDM in each project). The reason for that is “.” resolves to the directory where the exe is loaded from. If you want to reuse the same EDM, you at least have to make a few steps back in the path and then navigate to the project where the EDM is, e.g. “..\..\..\Proj1\AdventureWorksModel”. Additionally you may consider using the |DataDirectory| macro - when you load an AppDomain you can set |DataDirectory| to point to the exact directory where the EDM is, and then use that in the connection string, e.g. “|DataDirectory|\AdventureWorksModel”. If you are working on an ASP.NET project, you can use “~” which refers to the project root. In that latter case, you can’t reference a model outside your project’s hierarchy though.

     

     

    Zlatko Michailov

    Program Manager, Data Programmability Runtime

    Microsoft Corp.

     

    Monday, September 10, 2007 4:30 PM
    Moderator

All replies

  • My only guess is the app.config is not in the binary directory where the exe is. Please do the following:

    1.    Visually verify that the app.config with the expected content is in the directory where the exe is compiled. (Existence in the project root directory is not enough.)

    2.    Use System.Configuration.ConfigurationManager from within your app to examine the content of the app.config your exe is using.

     

    I’m also looking at the content of the connection string, and I can say that it may not work in a multi project environment (unless you’ve duplicated the EDM in each project). The reason for that is “.” resolves to the directory where the exe is loaded from. If you want to reuse the same EDM, you at least have to make a few steps back in the path and then navigate to the project where the EDM is, e.g. “..\..\..\Proj1\AdventureWorksModel”. Additionally you may consider using the |DataDirectory| macro - when you load an AppDomain you can set |DataDirectory| to point to the exact directory where the EDM is, and then use that in the connection string, e.g. “|DataDirectory|\AdventureWorksModel”. If you are working on an ASP.NET project, you can use “~” which refers to the project root. In that latter case, you can’t reference a model outside your project’s hierarchy though.

     

     

    Zlatko Michailov

    Program Manager, Data Programmability Runtime

    Microsoft Corp.

     

    Monday, September 10, 2007 4:30 PM
    Moderator
  • I resolved the connection error I reported at the top of this thread by copying the EDM connection string from the app.config file (where it was auto-generated by the EDM wizard) to the Web.Config file for my WCF web service (which that exposes my EDM entities).  My only feedback here would be that if the error message had reported which config file/project was missing the connection, the issue would have been easier to find (for someone new to EF).

     

    Once the Web.Config was updated, I got an error saying : {"The specified metadata path is not valid. A valid path must be either an existing directory, an existing file with extension '.csdl', '.ssdl', or '.msl', or a URI that identifies an embedded resource."}.  Copying the c/m/s files to the App_Data dir in my web project and updating my connection string to refer to the ~\App_Data\ location for the c/m/s files resolved this issue (I have not yet tried putting them in a different folder and using the |DataDirectory| macro instead).  It would be nice if there was a way to just auto deploy the connection and necessary files to where they need to go (as it is now I need to copy the revised c/m/s files from my EDM project to my web project every time I make a change to the EDM).

     

    Everything is working now, thanks for your help!

    • Proposed as answer by Vaccanoll Tuesday, July 05, 2011 7:08 PM
    Tuesday, September 11, 2007 11:48 PM
  • Ideally these binary files could be copied along with the assembly to the Bin directory's ASP.NET web application.

     

    Javier Luna

    Friday, November 02, 2007 8:12 PM
  • I am having the same issue but I think I found (possibly) part of the problem.

     

    Notice that when the Entity Data Model Wizard generates the ConnectionString for the Model it includes &quot; instead of a single '

     

    I changed the value from &quot; to a single quote, ', and noticed that the ConnectionString value in the Model Browser recognized the ConnectionString - whereas before the field was blank and greyed out.  Making this change did not fix the original problem that you posted but I thought that this might be part of the problem.  I am still working towards a solution after making this change.

    • Proposed as answer by Hans Braun Wednesday, February 17, 2010 6:08 PM
    Tuesday, February 12, 2008 6:57 PM
  •  Dave Black wrote:

    I am having the same issue but I think I found (possibly) part of the problem.

     

    Notice that when the Entity Data Model Wizard generates the ConnectionString for the Model it includes &quot; instead of a single '

     

    I changed the value from &quot; to a single quote, ', and noticed that the ConnectionString value in the Model Browser recognized the ConnectionString - whereas before the field was blank and greyed out.  Making this change did not fix the original problem that you posted but I thought that this might be part of the problem.  I am still working towards a solution after making this change.

    I replaced &quot; with a single ' and placed the connectionString section in the main app configuration file and it worked fine.

     

    thanks yall!

    • Proposed as answer by Asereware Wednesday, February 24, 2010 6:59 PM
    Wednesday, August 20, 2008 2:39 AM
  • AFAIK, this bug was fixed as part of VS 2008 SP1.  I assume that you are using SP1?

     

    Wednesday, August 20, 2008 2:48 AM
  •  Dave Black wrote:
    AFAIK, this bug was fixed as part of VS 2008 SP1.  I assume that you are using SP1?

     

    yes sir! SP1
    Wednesday, August 20, 2008 2:54 AM
  •  Márcio Martins wrote:
     Dave Black wrote:
    AFAIK, this bug was fixed as part of VS 2008 SP1.  I assume that you are using SP1?

     

    yes sir! SP1

     

    voilà!

    Wednesday, August 20, 2008 3:27 AM
  •  

    make sure your project refenerce the class library which includes .edmx also  has same connectstring generate by  edm wizard.I aslo have the same issue because my test project's config file   has not set connectstring.

    you should add  a class with the method using System.Configuration.ConfigurationManager.ConnectionStrings  to  debug where the problem is.

    VS 2008 SP1 has a bug with it? No,unacceptable.

     

     

    Wednesday, August 20, 2008 5:52 AM
  •  davin huang wrote:

     

    make sure your project refenerce the class library which includes .edmx also  has same connectstring generate by  edm wizard.I aslo have the same issue because my test project's config file   has not set connectstring.

    you should add  a class with the method using System.Configuration.ConfigurationManager.ConnectionStrings  to  debug where the problem is.

    VS 2008 SP1 has a bug with it? No,unacceptable.

     

     

     

     

    I was saying that the bug that initiated this Thread has been fixed in VS 2008 SP1.

    Wednesday, August 20, 2008 5:56 AM
  • VS 2008 SP1 may be fine, but C# Express 2008 SP1 still has this problem. I was able to replicate in 2 separate projects, on 2 different machines.
    Wednesday, August 20, 2008 8:40 PM
  •  

    I don´t know if it is a bug, but i was having the same problem.

     

    I have a WPF project and a Library class project. In the second, i have a Entity data model which was created with de VS 2008 asistant.

     

    The problem was solved when i copied the App.config of de library class project to de WPF project.

     

    I don´t kwon what is the problem, but i had VS 2008 SP1 when the problem arose.

    Thursday, August 21, 2008 11:40 AM
  •  Griffith Towsnend wrote:
    VS 2008 SP1 may be fine, but C# Express 2008 SP1 still has this problem. I was able to replicate in 2 separate projects, on 2 different machines.

     

    I have VS2008 Professional but I think the installer will detect the version and install appropriately.  That being said, I have only recently installed the .NET Framework 3.5 SP1 and VS2008 SP1 and have not yet had a chance to verify that this bug has been fixed.  I never did install the Beta version of with of the above because of all of the problems they had.  Note that SP1 must be installed in the order I mention above.

     

    I'm not sure if you ever had the Betas for .NET Framework 3.5 or VS2008 ever installed.  If so, then read more about installing the RTM of SP1 correctly here: http://blogs.msdn.com/heaths/archive/2008/08/11/vs-2008-sp1-beta-must-be-removed-prior-to-installing-the-release-of-vs-2008-sp1.aspx.  There is a SP1 "prep" tool that will help with uninstalling the SP1 Beta bits that must be run before installing the RTM SP1.

     

    I thought that this thread might be related to a bug I filed on MS Connect which has been labeled as Fixed and Closed.  See more here: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=328291.

     

    Hope this helps

    Thursday, August 21, 2008 4:07 PM
  •  Dave Black wrote:
     davin huang wrote:

     

    make sure your project refenerce the class library which includes .edmx also  has same connectstring generate by  edm wizard.I aslo have the same issue because my test project's config file   has not set connectstring.

    you should add  a class with the method using System.Configuration.ConfigurationManager.ConnectionStrings  to  debug where the problem is.

    VS 2008 SP1 has a bug with it? No,unacceptable.

     

     

     

     

    I was saying that the bug that initiated this Thread has been fixed in VS 2008 SP1.


    No it doesn't. I'm with SP1 and still get the same error on Professional or Team Suite but my solution some posts ago worked fine.
    Thursday, September 04, 2008 7:37 PM
  • Hi Guys,

     

    I had the same problem but resolved it. You need to add the EF connection string to the configuration file (app.config or web.config) in the caller code's project. For example if you have three tier app with DAL, BLL and a web layer, even though the Entity Model is in your DAL, you need to add the connection string node to youe web.config.

     

    Thursday, October 02, 2008 7:00 PM
  • I am having a testing console app call a wcf service (http binding). I changed the &quote; to ' in wcf web.config, but I still had to add the connectionstring to the console app's app.config file.

    STUPID.

    Thank you all for the help.
    Sunday, January 11, 2009 10:15 PM
  • I agree - so much for Seperations Of Concerns
    If my DataLayer uses EF and exposes the EntityTypes to my DomainLogic Layer, there is 0 reason why my DomainLogic layer needs to have the connection string included when searching and updating the Types

    I too changed the &quote to ' but also have to copy the connection string - which blows up seperation between my 2 layers

    Please Microsoft, fix this (or tell me how to fix it)
    Monday, February 02, 2009 10:27 PM
  • Same problem here.

    I've read the thread top to bottom twice now and tried all the suggestions but I'm still getting the problem. Maybe I'm missing something.


    1) I've got a WCF service which contains an edmx file. In its web.config it's got a connection string.

    2) I've also got a WPF app that has a web reference to the WCF service. It didn't have a connection string so I copied the one from the service into the WPFs config.

    3) I've also replaced the &quote with  " ' " 

    Here's the connection string I've got in both .config's.

    <connectionStrings> 
      <add name="ProdTodoDBEntities" connectionString="metadata=res://*/TodoListModel.csdl|res://*/TodoListModel.ssdl|res://*/TodoListModel.msl;provider=System.Data.SQLite;provider connection string='data source=|DataDirectory|TodoDB.sqlite'" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 



    But there's been no change.

    Is there anything further that people can suggest?


    Sunday, February 08, 2009 4:31 PM
  • asdf989 said:

    Same problem here.

    I've read the thread top to bottom twice now and tried all the suggestions but I'm still getting the problem. Maybe I'm missing something.


    But there's been no change.

    Is there anything further that people can suggest?



    I just figured out my problem thanks to this post.

    http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/70f124b6-5003-4011-8142-9c7e4ac6c4a0/

    It seems that its crucial that the ConnectionString be named after the ObjectContext to which is represents.
    I had been trying to setup Production vs Development connection strings and therefore altered the names of the strings to be "DevTodoEntities" and "prodTodoEntities".






    Sunday, February 08, 2009 5:29 PM
  • @asdf989

    Thank you man!! , i resolved it.

    Tuesday, February 10, 2009 10:08 AM
  • Thanks :)
    Thursday, October 08, 2009 4:26 PM
  • I spent hours last night fighting this issue and somehow my Google queries never brought me to this post. Today, your answer helped in minutes. Thank you.
    Tuesday, October 13, 2009 7:54 PM
  • The same solution is working fine for mi.

    Thanks you all.
    Asereware
    Wednesday, February 24, 2010 7:02 PM
  • Thanks!!!!

    This thing is working fine with me....

    :)

    Stay Blessed Stay safe....

    Happy Coding!!!
    Wednesday, March 03, 2010 8:29 AM
  • I had the same problem (VS 2010 RTM). I had two projects, a model and a view/viewmodel project. The app.config was in my model. I copied it from the model project to the view/viewmodel project and it fixed the problem. I also had to replace the html style quotes with ticks (').
    Thursday, March 11, 2010 8:44 PM
  • I am having the same problem, but with a twist.  I have a project with my EF model, and another project with a form which references the model, and also a unit test project that instantiates the form.  I copied the .config file to each project and they all work from VS.  However, the project with the form is an interop project that I'm calling from Delphi.  You know what's coming next: The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid. So now I'm trying to figure out what .config file its looking for and where.  I've tried renaming app.config to the name of my executable and putting that in the folder with my executable as well as the folder where the .dll is, but neither of them work.  Any suggestions would be greatly appreciated.

    Thanks,

    Welton

    Monday, April 12, 2010 10:36 PM
  • You might also want to check the applicationbase and configuration file name properties in the project editor from the nUnit GUI. The nUnit GUI is not (necessarily) looking for your vs projects app.config. When i inspected the ConfigurationManager.connectionstring contents i found that my connectionstring to the EF store was not loaded.

    success!

    Friday, April 30, 2010 9:10 AM
  • I'm using VS2010 (Release) Professional, with Silverlight4 and Silverlight4 Tools to develop a RIA app (I'm using Nikhil Kothari's BookClub as an example, although I have the same issues with other databases I've tried, where the data is provided by Entity Framework). Entity Framework fails with The specified named connection is either not found in the configuration, not intended to be used with the EntityClient Provider, not valid. I have tried:

    1. Calling from the Silverlight client app. ==> blank screen as a result of exception
    2. Calling from a Test app. ==> Exception
    3. Setting web.config properties to Always Copy to the output folder.
    4. Manually copying web.config to every bin folder in the solution.
    5. Replacing &quot; with single quotes in the web.config Connection String.
    6. Blowing the solution away and starting over (five times).
    7. Putting a literal connection string into the call to create the ObjectContext. This works in tests, thus proving that the problem is to do with configuration.

    What am I missing?

    Any assistance from the assembled minds on this forum will be most gratefully accepted.

      Dave.

    Friday, May 28, 2010 4:18 AM
  • I had the same problem with a project that was working in VS 2010. For some reason the Entity Model generator stopped putting the connection string in Web.Config completely even though the "create connection string" checkbox was checked.

    I created a new project, added a new model that referenced the database, and then copied that connection string in my Web.Config and the project is working again.

    Don

    Friday, May 28, 2010 2:03 PM
  • I had this from within a WinForm project so I copied the App.Config connection strings into the calling application's App.Config. All well now...

    Wednesday, September 08, 2010 11:25 AM
  • Hi,


    I am building a wcf solution with Entity Framework4 (I installed CTP 4).

    When I run the application, I got the following error:
    The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.

    I have client, host, service and data access layer projects in my solutin.

    the DAL project is in the folder D:\DotNet Execises\EF\DAL
    the Service project is in the folder D:\DotNet Execises\EF\Service
    the Service project is in the folder D:\DotNet Execises\EF\Host
    the Client project is in the folder D:\DotNet Execises\EF\Client

    the PatientModal.edmx file is in the DAL project.

    the connection string in the app.config for DAL is
    <add name="PatientEntities" connectionString="metadata=res://*/PatientModel.csdl|res://*/PatientModel.ssdl|res://*/PatientModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=PETERSHAW-PC\SQLEXPRESS;Initial Catalog=PMS;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />


    I copied the connection string in the app.config of the DAL project into Client project's app.config, I copied the app.config into service project. These did not help.

    I tried to chang the connction string as

    <add name="PatientEntities" connectionString="metadata=..\..\..\DAL\obj\Debug\edmxResourcesToEmbed\PatientModel.csdl|..\..\..\DAL\obj\Debug\edmxResourcesToEmbed\PatientModel.ssdl|..\..\..\DAL\obj\Debug\edmxResourcesToEmbed\PatientModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=PETERSHAW-PC\SQLEXPRESS;Initial Catalog=PMS;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />

    It did not work either.

    I also built a test solution that everything is in the same project. The program runs well without the error message.

    So how to fix the problem?


    • Proposed as answer by BBirajdar Tuesday, November 16, 2010 11:22 AM
    Monday, October 25, 2010 5:08 AM
  • None of the tricks on this page worked for me..

    This was a utter $^%(*&^ ...

    I passed the entityconnectionstring to all the instances of the objectContext classes and its working now.

    But its a too much overhead, creating a property with connectionstring and passing it as a parameter to each instance

     

     

     

    Tuesday, November 16, 2010 11:24 AM
  • Hi BBirajdar,

     

    I solved the problem by add the connection string into host project's app.config. Hope this help you.

     

    Tuesday, November 16, 2010 10:31 PM
  • Hello Terry,

    One of the reason for getting this error is because of one of the project may not be able to locate the data source specified in the entity model. You try the following procedure to avoid the error,

    1. Check for "App.Config" file in each of the project in the Solution

    2. If "App.Config" is not there in any project then, Right Click the project >>add new item>>Web>> Web Configuration File. Name it as "App.config" and add it to the project. Then, Open the recently added "App.Config" and add your connection string inside the Configuration tags.

    In the above case copy the whole configuration tag and paste in the recently added "App.Config"

    3. If all project have "App.Config", then add the your connection string[Inside the Configuration tag] to those "App.Config" files which don't have it.

     

    Hope it helps,

    Eldhose Mani


    • Proposed as answer by Eldhose Mani Friday, July 15, 2011 11:25 AM
    Monday, June 27, 2011 9:16 PM
  • Hi,

    I had the simiar problem. Solution I found is:

    Copied the app.config's DB setting to web.config, and it worked fine for me.

    This might an alternative solution...

    Regards,

    Deepak Shaw

     

    Friday, July 08, 2011 11:24 AM
  • My only guess is the app.config is not in the binary directory where the exe is. Please do the following:

    1.    Visually verify that the app.config with the expected content is in the directory where the exe is compiled. (Existence in the project root directory is not enough.)

    2.    Use System.Configuration.ConfigurationManager from within your app to examine the content of the app.config your exe is using.

     

    I’m also looking at the content of the connection string, and I can say that it may not work in a multi project environment (unless you’ve duplicated the EDM in each project). The reason for that is “.” resolves to the directory where the exe is loaded from. If you want to reuse the same EDM, you at least have to make a few steps back in the path and then navigate to the project where the EDM is, e.g. “..\..\..\Proj1\AdventureWorksModel”. Additionally you may consider using the |DataDirectory| macro - when you load an AppDomain you can set |DataDirectory| to point to the exact directory where the EDM is, and then use that in the connection string, e.g. “|DataDirectory|\AdventureWorksModel”. If you are working on an ASP.NET project, you can use “~” which refers to the project root. In that latter case, you can’t reference a model outside your project’s hierarchy though.

     

     

    Zlatko Michailov

    Program Manager, Data Programmability Runtime

    Microsoft Corp.

     

    This post helped me too.
    I copied my app.config for the test project and it worked perfectly.

    Thanks.
    Friday, August 05, 2011 7:52 PM
  • i had the same problem.

    the reason was because of a declarative binding of a control

    i had changed the model name, but the bound controls were set to the old connection

     

    <asp:EntityDataSource ID="ParentAcademyDataSource" runat="server"
        ConnectionString="name=UniversityDBEntities"
        DefaultContainerName="UniversityDBEntities" EnableFlattening="False"
        EntitySetName="Academies" Select="it.[Title], it.[ID]">
    </asp:EntityDataSource>

    Tuesday, August 23, 2011 6:12 AM
  • Hi Guys,

     

    I had the same problem but resolved it. You need to add the EF connection string to the configuration file (app.config or web.config) in the caller code's project. For example if you have three tier app with DAL, BLL and a web layer, even though the Entity Model is in your DAL, you need to add the connection string node to youe web.config.

      

    Hi,

    Same problem here.

    I have a multi tier app that has a DAL project. This DAL project is the provider of the entities for my Silverlight client and my Winforms client.

    The only way I can get this to work is to copy the connectionstring from the App.Config (auto generated by the EDM Wizard) file of the DAL project (Class Library) to the Web.Config of the Silverlight project and to copy it to the App.Config of the WinForms project.

    It took me hours to figure this one out. Using the webservce to get data from the DAL just returned errors like "Server not found". It was the winforms executable that actually gave me some clues about the connection string for EF.

    Are there ways to just keep the conn.string in the DAL project itself or am I missing the point here...

    Basically it is the only project in my solution that really uses the conn.string to create a new instance of the ObjectContext. The other projects just act as clients that need to show some sort of data....

    I would really appreciate some input on this.....

     

     

    Thursday, September 22, 2011 8:36 PM
  • Had this error earlier today, took a while to figure it out. Having copied the app.config file across into the new project I got this error. Took me a while to think of adding it to the solution explorer window in VS. Once that was done everything started working nicely.
    Monday, October 17, 2011 1:15 PM
  • Just a thought, have people checked that they are in the correct web.config or app.config? There are two (for some reason) in my project and I was adding the connection string into the wrong one and couldn't understand why I was still getting the error. Easily done and baffling until you figure out what's going on. 
    Thursday, January 26, 2012 10:16 AM
  • Thank you so much M. Michailov! Good tip to see which config is used.

    Solved!

     

    Thanks again,

     

    Jsr.

     

    Sunday, February 05, 2012 5:37 AM
  • I'm having the same issue. Nothing above has resolved my issue. What is strange is that everything builds fine and runs fine. I see the expected data.

    I have a simple WPF app with the model part of it (its a test app). No code has changed since Sept 2011. App.config is the same with the same connection.

    This only started to happen after migrating to a new laptop.

    Thoughts?

    Wednesday, March 07, 2012 10:32 PM
  • I solved this issue, please see image as below :

    Sunday, June 17, 2012 1:51 PM
  •  
    it doesn't look at the app.config in the BLL project. It looks for it in
    the root project, which is the Windows form project. It look for it in
    the Web.Config project(the root project) and not in the BLL project and
    the app,config it it was a Web project.
     
    Sunday, June 17, 2012 6:02 PM
  • FOR WEB Application

    Move the connection string in App.config File in Class library project to Web Application Place in Web.config then run your project 

    FOR WINDOW Application

    Move the connection string in App.config File in Class library project to Window Application Place in App.config then run your project 


    Sunday, August 12, 2012 7:00 AM
  • It worked for me too. But then, when a connection string is available in the EF Project's App.config file, why should the framework expect the connection string to be available from the calling project also? When the Context Object is getting instantiated, it does not know which is the calling Project. So, why should it need the connection string from the calling Project?
    Friday, January 18, 2013 7:01 AM
  • On 1/18/2013 2:01 AM, Sukin wrote:
    > It worked for me too. But then, when a connection string is available in
    > the EF Project's App.config file, why should the framework expect the
    > connection string to be available from the calling project also? When
    > the Context Object is getting instantiated, it does not know which is
    > the calling Project. So, why should it need the connection string from
    > the calling Project?
     
    The EF app.config entries in the app.config in the EF project must be
    moved to the root config file. That's means that an app.config must be
    created in the project that is calling the EF project. Or if there is a
    project that is calling the project that is calling the EF project, then
    an app.config must be made in first project with the EF entries placed
    in the first project's app.config.
     
    What is being talking about is the root.config of the solution whether
    that be an app.config or Web.config. .NET looks for configuration
    information in the root config. You can have 1,000 app.configs in the
    solution, but .NET is only going to look at one app.config for config
    information for the .NET solution, and that is the root config or root
    app.config or root Web.config.
     
    As an example, you have a Web page that is calling the EF project. The
    EF project has the app.config with the config info in that project. .NET
    is not looking at the app.config at the EF project level. It's looking
    for config information to be in the Web.config of the Web project for
    the EF configuration.
     
    So in your case, you have to make a app.config in the root project if
    there is not there and copy the EF entries,  or if the app.config is all
    ready there, then the EF entries must be merged into that app.config.
     It's talking about Web and App.config and the 'root'.
     
     
    Friday, January 18, 2013 7:36 AM