Setting the Connection String in MVC Asp.Net Application

Leave a Comment

You don't have to create a connection string. If you don't create one, the Entity Framework will automatically create a SQL Server Express database for you. In this tutorial, however, you'll work with SQL Server Compact, so you need to create a connection string to specify that.

Open the project Web.config file and add a new connection string to the connectionStrings collection, as shown in the following example. (Make sure you update the Web.config file in the root project folder. There's also a Web.config file is in the Views subfolder that you don't need to update. )
<add name="SchoolContext" connectionString="Data
Source=|DataDirectory|School.sdf" providerName="System.Data.SqlServerCe.4.0"/>

By default, the Entity Framework looks for a connection string named the same as the object context class. The connection string you've added specifies a SQL Server Compact database named School.sdf located in the App_Data folder.

0 comments:

Post a Comment