codefirst期间的EF在localdb中失败

时间:2015-11-29 17:51:22

标签: asp.net-mvc entity-framework ef-code-first

我的InnerException {"The underlying provider failed on Open."}中出现了下一个错误 当我发布到Azure时,一切正常,但在localhost上崩溃。

ConnectionString

<add name="AccountingDBContext" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\AccountingDB.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />

在网络上写下一个错误

Cannot attach the file 'D:\AccountingWebApplication\AccountingWebApplication\App_Data\AccountingWebApplication.Db.AccountingContext.mdf' as database 'AccountingWebApplication.Db.AccountingContext'.

1 个答案:

答案 0 :(得分:0)

您的配置文件是否设置为使用localdb?

<entityFramework>
 <defaultConnectionFactory 
  type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, 
        EntityFramework">
<parameters>
  <parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
</entityFramework>