Asp.net mvc 我的项目在App_数据文件夹中搜索.mdf文件、web.config设置

Asp.net mvc 我的项目在App_数据文件夹中搜索.mdf文件、web.config设置,asp.net-mvc,asp.net-mvc-4,Asp.net Mvc,Asp.net Mvc 4,我正在从事MVC项目。现在我正在使用SQL server本地数据库 我的项目是用MVC项目和数据层项目构建的。类库 控制器必须从/向ViewsMVC获取/向DataLayer传递数据 我面临Web.Config和App.Config的问题 在运行该项目时,我遇到以下错误 我很困惑为什么它要找App_数据文件夹 {"The underlying provider failed on Open."} {"Cannot attach the file 'D:\\BackUp\\5 may 2014\\

我正在从事MVC项目。现在我正在使用SQL server本地数据库

我的项目是用MVC项目和数据层项目构建的。类库

控制器必须从/向ViewsMVC获取/向DataLayer传递数据

我面临Web.Config和App.Config的问题

在运行该项目时,我遇到以下错误

我很困惑为什么它要找App_数据文件夹

{"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>

请尝试使用如下连接字符串:


数据源=。\SQLEXPRESS;AttachDbFilename=| DataDirectory | DatabaseName.mdf;综合安全=真实;用户实例=True

在哪里?在web.config或App.config中?将其放在web.configNo中,它仍在查找Add_Data文件夹