问题描述:

Am trying to follow this link http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/accessing-your-model%27s-data-from-a-controller to get started.

While creating Entity using code First approach , how can i create .mdf in VS. What should be my connection string ?

my connectionstring

<add name="MovieDBContext"

connectionString="Data Source=|DataDirectory|Movies.mdf"

providerName="System.Data.EntityClient"/>

Am getting error in DataSource while creating controller. wat should the Data Source for .MDF ?

网友答案:

If you're trying to use LocalDb (i.e. mdf)

  • The providerName needs to be "System.Data.SqlClient" for a start.
  • Then your connection string needs a bit more info, like this:

    "Data Source=(LocalDb)\v11.0;Initial Catalog=yourDbName;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\Movies.mdf"

If you wantng to use SqlServerCe (sdf) then:

  • The providerName needs to be "System.Data.SqlServerCe.4.0"
  • connection string:

    "Data Source=|DataDirectory|Movies.sdf"

相关阅读:
Top