locked
Entity Framework and connection strings RRS feed

  • Question

  • I'm trying to create my first EF data model. I had to delete the first version because of errors, everything, edmx and tt files. Now when I try to add a new ADO.NET Entity Data Model again, I cannot use the same name for the connection string - the wizard says it already exists in Application Settings. I would like to remove it, but can't find it -there is no app.setting file, appSetting in the web.config does not have connection strings. Where is it?

    Thank you!


    olga

    Tuesday, February 5, 2013 12:19 AM

Answers

  • On 2/18/2013 8:58 PM, knit wrote:

    Never found app.config. It's an MVC 3 application. When open in Visual Studio, app.config is nowhere to be seen. That was my initial question, where else should I look for it? I can see now I should have mentioned MVC in the first post.

    If you are saying that you added a new item to this Web project and the item was EF, then the connection string for EF was placed in the Web.config. Why you cannot see that connection string, I don't know. However, that connection string is there in the Web.config.


    I re-created the project, and it's working fine (no app.config in the new project either). Still curious, where was that app.config.

    The EF connection string is going to be in an app.config when you have added EF as a new item, to a Window, Console, Classlib, Service or WPF project type.

    Again, if you added EF as new item in that Web project, then EF has put the connection string in the Web.config. I just verified this, created a new Web project and added EF as a new item to the project. And the connection string for EF is in the Web.config.
     Web UI layer,  Business Logic Layer and Data Access Layer both BLL and DAL are  classlib projects with the DAL having EF, then the app.config with the connection string is created in the DAL project. You would have to copy and paste that connection string that was created in the DAL in its app.config to the Web.config in order for .NET to find the connection string. .NET will not look for the connection string in the app.config at the DAL in this example of a N-Tier Web application using MVC or MVP or not using either one of the UI design patterns. The connection string in the DAL must be moved to the Web.config in order for .NET to find the database and access it.

    • Marked as answer by Alexander Sun Tuesday, February 26, 2013 6:46 AM
    Tuesday, February 19, 2013 5:01 AM

All replies

  • On 2/4/2013 7:19 PM, knit wrote:
    > I'm trying to create my first EF data model. I had to delete the first
    > version because of errors, everything, edmx and tt files. Now when I try
    > to add a new ADO.NET Entity Data Model again, I cannot use the same name
    > for the connection string - the wizard says it already exists in
    > Application Settings. I would like to remove it, but can't find it
    > -there is no app.setting file, appSetting in the web.config does not
    > have connection strings. Where is it?
    >
     
    There is an app.config at the project level for the ADO.NET Entity
    Framework project. That's where the connection string is created. Of
    course,  you should know that you must copy the connection string to the
    Web.config so that the Web application can find the connection string
    and use it to access the database using the Entity Framework at runtime.
     
    Tuesday, February 5, 2013 3:59 AM
  • Hi,

    Were you able to find the source of your problem here?

    As was said earlier in the thread, EF will create an app.config in the root of whatever project it is in when you run the wizards. So if your model was in a class library then it will have created an app.config there.


    We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.

    Monday, February 18, 2013 11:59 PM
  • Never found app.config. It's an MVC 3 application. When open in Visual Studio, app.config is nowhere to be seen. That was my initial question, where else should I look for it? I can see now I should have mentioned MVC in the first post.

    I re-created the project, and it's working fine (no app.config in the new project either). Still curious, where was that app.config.

    Thank you all. I will switch to Stack Overflow.


    olga

    Tuesday, February 19, 2013 1:58 AM
  • On 2/18/2013 8:58 PM, knit wrote:

    Never found app.config. It's an MVC 3 application. When open in Visual Studio, app.config is nowhere to be seen. That was my initial question, where else should I look for it? I can see now I should have mentioned MVC in the first post.

    If you are saying that you added a new item to this Web project and the item was EF, then the connection string for EF was placed in the Web.config. Why you cannot see that connection string, I don't know. However, that connection string is there in the Web.config.


    I re-created the project, and it's working fine (no app.config in the new project either). Still curious, where was that app.config.

    The EF connection string is going to be in an app.config when you have added EF as a new item, to a Window, Console, Classlib, Service or WPF project type.

    Again, if you added EF as new item in that Web project, then EF has put the connection string in the Web.config. I just verified this, created a new Web project and added EF as a new item to the project. And the connection string for EF is in the Web.config.
     Web UI layer,  Business Logic Layer and Data Access Layer both BLL and DAL are  classlib projects with the DAL having EF, then the app.config with the connection string is created in the DAL project. You would have to copy and paste that connection string that was created in the DAL in its app.config to the Web.config in order for .NET to find the connection string. .NET will not look for the connection string in the app.config at the DAL in this example of a N-Tier Web application using MVC or MVP or not using either one of the UI design patterns. The connection string in the DAL must be moved to the Web.config in order for .NET to find the database and access it.

    • Marked as answer by Alexander Sun Tuesday, February 26, 2013 6:46 AM
    Tuesday, February 19, 2013 5:01 AM