環境 vs2012
框架 mvc3
數據庫 sqlservercompact4.0
出現的錯誤如下:
“
---------------------------
Microsoft Visual Studio
---------------------------
無法檢索“MvcMusicStore.Models.Album”的元數據。Using the same DbCompiledModel to create contexts against different types of database servers is not supported. Instead, create a separate DbCompiledModel for each type of server being used.
---------------------------
確定
---------------------------
”
解決辦法:http://stackoverflow.com/questions/12410673/using-the-same-dbcompiledmodel-to-create-contexts-against-different-types-of-dat
“
I switched providerName="System.Data.SqlServerCe.4.0" with providerName="System.Data.SqlClient", and it created the Controller and Views.
OK, so switching to providerName="System.Data.SqlClient" will get the controller and the views built, but the site won't run. If after using the switch to build the controller, you then switch it back to providerName="System.Data.SqlServerCe.4.0", it will then run. It's not pretty, but it should get you through the tutorial.
”
分為兩部分
第一就是把webconfig中的數據庫配置 providerName="System.Data.SqlServerCe.4.0 修改成 providerName="System.Data.SqlClient" 這樣就可以添加成功控制器了
第二 生成控制器以后 在把 providerName="System.Data.SqlClient 改回 providerName="System.Data.SqlServerCe.4.0 就OK了
沒有第二部的話 也就是說不還原回去的話 會報如下錯誤:
“
[Win32Exception (0x80004005): 找不到網絡路徑。] [SqlException (0x80131904): 在與 SQL Server 建立連接時出現與網絡相關的或特定於實例的錯誤。未找到或無法訪問服務器。請驗證實例名稱是否正確並且 SQL Server 已配置為允許遠程連接。 (provider: Named Pipes Provider, error: 40 - 無法打開到 SQL Server 的連接)]
”
