0
我正在從事MVC項目。 (現在我正在使用SQL服務器,本地數據庫)我的項目搜索到.mdf文件的App_Data文件夾,web.config設置
我的項目使用MVC項目和數據層項目構建。 (Class Library)
控制器必須從/ To DataLayer從/ To Views(MVC)獲取/傳遞數據。
我面臨着Web.Config和App.Config的問題。
運行該項目時出現以下錯誤。
我很困惑abt爲什麼它尋找App_Data文件夾?
{"The underlying provider failed on Open."}
{"Cannot attach the file 'D:\\BackUp\\5 may 2014\\MyDBname\\App_Data\\MyDBname.mdf' as database 'MyDBname'."}
這裏是我的web.config的代碼
<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="SchoolContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=MyDBname;Integrated Security=SSPI;" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
這裏是我的app.config的代碼
<?xml version="1.0"?>
<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"/>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0; Initial Catalog=MyDBname;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
</providers>
</entityFramework>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
哪裏?在web.config或在App.config? – bnil
把它放在Web.config中 –
不,它仍然在尋找Add_Data文件夾 – bnil