1

我正在通過this tutorial,我被困在第5步 - 創建連接字符串和使用SQL Server LocalDB。我得到的錯誤是:ASP.NET MVC 5教程和LocalDB簡介

There was an error running the selected code generator: 

'Unable to retrieve metadata for 'MvcMovie.Models.Movie'. Unable to find the requested .Net Framework Data Provider. It may not be installed.' 

我已經在網上搜索了好幾天答案。我嘗試了很多解決方案,但都沒有成功。我已經檢查並重新檢查了代碼,我在Windows 7 64位PC上安裝了Visual Studio Express 2013 for Web和更新1。任何人都可以幫我解決使用LocalDB而不是另一個數據庫產品?

這裏是web.config中:

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
    For more information on how to configure your ASP.NET application, please visit 
    http://go.microsoft.com/fwlink/?LinkId=301880 
    --> 
<configuration> 
    <configSections> 
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <connectionStrings> 
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MvcMovie-20140207025827.mdf;Initial Catalog=aspnet-MvcMovie-20140207025827;Integrated Security=True" 
     providerName="System.Data.SqlClient" /> 
    <add name="MovieDBContext" 
     connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Movie.mdf;Initial Catalog=Movies;Integrated Security=True" 
     providerName="System.Data.SqlClient" 
    /> 

    </connectionStrings> 
    <appSettings> 
    <add key="webpages:Version" value="3.0.0.0" /> 
    <add key="webpages:Enabled" value="false" /> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
    </appSettings> 
    <system.web> 
    <authentication mode="None" /> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5" /> 
    </system.web> 
    <system.webServer> 
    <modules> 
     <remove name="FormsAuthenticationModule" /> 
    </modules> 
    </system.webServer> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> 
     <parameters> 
     <parameter value="v11.0" /> 
     </parameters> 
    </defaultConnectionFactory> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
    </entityFramework> 
</configuration> 

我已經回答了在ASP.NET論壇的一些問題,並張貼屏幕截圖,請閱讀過 - Here

+0

我要在黑暗中刺傷......你有沒有嘗試在你的第二個連接字符串中包含「集成安全性? – PlTaylor

+0

看來您的網站正在尋找app_data中的localDb文件。它在那裏嗎? –

+0

MovieDBContext連接字符串確實包含Integrated Security = true。沒有localDb沒有顯示在app_data中。根據教程,我得到錯誤的步驟應該添加它。 – Neil

回答

0

對不起,這是一臺計算機的問題。我能夠在另一臺電腦上做同樣的事情。

1

請修改連接字符串如下圖所示:

<add name="MovieDbContext" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True" providerName="System.Data.SqlClient" /> 

您可以查看下面的文章進一步參考:

http://www.c-sharpcorner.com/UploadFile/4b0136/working-with-model-class-and-connection-string-in-mvc-5/

請檢查您的應用程序的事件查看器詳細信息。如果LocalDb已損壞,請運行以下命令:

SqlLocalDB Create C