none
No connection string named '' could be found in the application config file RRS feed

  • Question

  • Creating my first Entity Framework "Hello World" app, no problem and data displayed.  But when I did a new one and added the model to my class library project (instead of it all being in one project), I get the error:

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

    I read something that said the connection string had to be in the client but, of course, that can't be the case.  What am I doing wrong?  thanks

    Wednesday, March 26, 2014 4:27 AM

Answers

  • Hi,

    >> Here is what I pasted.  Do I need to modify it first or something?  I'm confused why the client project would need the connection info.  thanks guys

    Yes, that should be ok. For why the client project would need the connection info, it is described in my first it will not copy the conifg file to your target project.

    >> No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'.

    Do you alse install the same version with in your final project? If not, please install it, if you already did it. I am confused why it throws such an error and here I made a gif to show it:

    Create A Model using Class Library and A Targer Project using Console Application with being installed boh EF6:

    Adding a reference to target project and copying the connection string and calling the model:

    If I do not copy the connection string, it will throw the error “No connection string named '' could be found in the application config file”.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 27, 2014 9:57 AM
    Moderator
  • When a context gets generated it normally has the connection string set to the same name as the context so it would be worth checking that there isn't a problem there. That way as long as the connection string name is ok you should be able to just use the original EF connection string in the client web.config.

    Or you can comment out the "throw new UnintentionalCodeFirstException();" line from OnModelCreating to use the normal connection string.

        public partial class testEntities : DbContext
        {
            public testEntities()
                : base("name=testEntities1")
            {
            }
        
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                //comment out this line to allow for a normal connection string 
                throw new UnintentionalCodeFirstException(); 
            }
        
            public virtual DbSet<Table_1> Table_1 { get; set; }
        }

    Thursday, March 27, 2014 7:22 AM

All replies

  • You will need to add the connection to the app.config of the assembly which is using your class (so basically your startup project).
    Wednesday, March 26, 2014 4:31 AM
  • Hello coojbs,

    The app/web.config file will not be added to your startup project from the referenced assembly. So you can do what JayChase said "You will need to add the connection to the app.config of the assembly which is using your class ".

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 26, 2014 6:46 AM
    Moderator
  • You mean just copy and paste the below from the app.config file of my class library into the web.config file of my client app?  I did but got this error:

    No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'.

    Here is what I pasted.  Do I need to modify it first or something?  I'm confused why the client project would need the connection info.  thanks guys

      <connectionStrings>

        <add name="COWFeedyardEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\;initial catalog=COWFeedyard;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

      </connectionStrings>


    Wednesday, March 26, 2014 8:15 PM
  • It should work if you take just the connection string part out and use the with System.Data.SqlClient as the provider.

      <connectionStrings>
        <add  name="COWFeedyardEntities" connectionString="data source=.;initial catalog=COWFeedyard;integrated security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />   
      </connectionStrings>

    Thursday, March 27, 2014 12:57 AM
  • I greatly appreciate the help, but I'm not getting this to work.  When I paste that in the web.config I now get the below error.  I was trying to see if EF was viable for us or a big learning curve.  So far, I can't even get my tiny little proof-of-concept to work!

    Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes, that were generated from Database First or Model First, with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception.
     

    Thursday, March 27, 2014 3:35 AM
  • When a context gets generated it normally has the connection string set to the same name as the context so it would be worth checking that there isn't a problem there. That way as long as the connection string name is ok you should be able to just use the original EF connection string in the client web.config.

    Or you can comment out the "throw new UnintentionalCodeFirstException();" line from OnModelCreating to use the normal connection string.

        public partial class testEntities : DbContext
        {
            public testEntities()
                : base("name=testEntities1")
            {
            }
        
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                //comment out this line to allow for a normal connection string 
                throw new UnintentionalCodeFirstException(); 
            }
        
            public virtual DbSet<Table_1> Table_1 { get; set; }
        }

    Thursday, March 27, 2014 7:22 AM
  • Hi,

    >> Here is what I pasted.  Do I need to modify it first or something?  I'm confused why the client project would need the connection info.  thanks guys

    Yes, that should be ok. For why the client project would need the connection info, it is described in my first it will not copy the conifg file to your target project.

    >> No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'.

    Do you alse install the same version with in your final project? If not, please install it, if you already did it. I am confused why it throws such an error and here I made a gif to show it:

    Create A Model using Class Library and A Targer Project using Console Application with being installed boh EF6:

    Adding a reference to target project and copying the connection string and calling the model:

    If I do not copy the connection string, it will throw the error “No connection string named '' could be found in the application config file”.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 27, 2014 9:57 AM
    Moderator
  • Any update? I have marked my and JayChases replys as answer sicne I think they are helpful, if you think it provides no help, please unmark it.

    Thank you for your understanding and support.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, April 2, 2014 7:43 AM
    Moderator
  • Thak's  a lot… you save me.
    Sunday, June 1, 2014 3:49 AM
  • Thank you very much.. It helps me a lot..

    Tuesday, June 17, 2014 5:03 AM
  • thank you very much
    Friday, August 12, 2016 1:01 AM