How to: Define the Connection String

This topic shows how to define the connection string that is used when connecting to a conceptual model. This topic is based on the AdventureWorks Sales conceptual model. The AdventureWorks Sales Model is used throughout the task-related topics in the Entity Framework documentation. This topic assumes that you have already configured the Entity Framework and defined the AdventureWorks Sales Model. For more information, see How to: Manually Define the Model and Mapping Files. The procedures in this topic are also included in How to: Manually Configure an Entity Framework Project.

Note

If you use the Entity Data Model Wizard in a Visual Studio project, it automatically generates an .edmx file and configures the project to use the Entity Framework. For more information, see How to: Use the Entity Data Model Wizard

To define the Entity Framework connection string

  • Open the project's application configuration file (app.config) and add the following connection string:

    <connectionStrings>
        <add name="AdventureWorksEntities" 
             connectionString="metadata=.\AdventureWorks.csdl|.\AdventureWorks.ssdl|.\AdventureWorks.msl;
             provider=System.Data.SqlClient;provider connection string='Data Source=localhost;
             Initial Catalog=AdventureWorks;Integrated Security=True;Connection Timeout=60;
             multipleactiveresultsets=true'" providerName="System.Data.EntityClient" />
    </connectionStrings>
    

    If your project does not have an application configuration file, you can add one by selecting Add New Item from the Project menu, selecting the General category, selecting Application Configuration File, and then clicking Add.

See Also

Concepts

Quickstart

Other Resources

How to: Create a New Conceptual Model
Entity Data Model Tools