当前位置: 动力学知识库 > 问答 > 编程问答 >

asp.net mvc - Code first Entity framework connection string

问题描述:

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"

分享给朋友:
您可能感兴趣的文章:
随机阅读: