我正在将ASP.NET webforms网站迁移到新服务器。在旧服务器上,我的数据库位于网站根目录的App_Data文件夹中。在我的新服务器上,我将数据库放在root之外的另一个文件夹中,并且一切正常。
但有些奇怪的事情发生了。当我去网站浏览时,突然在我的站点的根文件夹中创建了一个App_Data文件夹,其中包含一个名为ASPNETDB.MDF的数据库。我可以删除它,但过了一会儿就会再次出现。
我做了一些测试和尝试,我发现在运行此代码时正在创建数据库:
TestLabel.Text = Profile.MyProfileParameter.ToString();
所以我认为必须是被调用的Profile导致它。 在我的web.config中,我有以下内容:(有点减少,我有更多的配置文件参数)
<profile enabled="true">
<properties>
<add name="MyProfileParameter" type="Int32" defaultValue="30"/>
</properties>
</profile>
在我的web.config中稍高一点我有连接字符串指向我的根文件夹之外的数据库:
<connectionStrings>
<add name="ConnectionString" providerName="System.Data.SqlClient"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=TheNameOfMyDatase;Integrated Security=True;MultipleActiveResultSets=True" />
</connectionStrings>
有人知道为什么调用配置文件会生成数据库吗? 这不是一个真正的表演限制,但我想知道为什么会发生这种情况。
一些额外信息:
SOLUTION:
显然我还有很多东西要学习web.config。
除了web.config之外,还有一个来自web.config的machine.config继承。
在<profile>
部分的此计算机配置中,有以下设置:
<profile>
<providers>
<add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
</profile>
可以在web.config中重写此设置
首先(我认为这不是必要的)我通过向<connectionStrings>
添加一个清除命令从连接字符串中删除localSqlServer:
<connectionStrings>
<!-- clear command removes localSqlServer from machine.config -->
<clear />
<add name="ConnectionString" providerName="System.Data.SqlClient"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=TheNameOfMyDatase;Integrated Security=True;MultipleActiveResultSets=True" />
</connectionStrings>
如果我现在运行我的网站,则会收到错误消息,指出找不到连接名称“LocalSqlServer”。
所以我在<profile>
部分添加了一个新的提供程序,并将其指向我的ConnectionString
<profile enabled="true">
<providers>
<!-- clear command removes localSqlServer from machine.config -->
<clear/>
<add name="AspNetSqlProfileProvider" connectionStringName="ConnectionString" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</providers>
现在一切正常,没有更多的数据库突然出现。
感谢ijaz发出指示,奖金是你的!
答案 0 :(得分:1)
AspNetdb是Asp.Net成员资格提供程序或其他应用程序服务(如“配置文件,角色/权限等)使用的数据库。生成的.mdf文件是一个数据库(SQL 2005 express)。
当您在ASP.NET中使用标准sql提供程序时,它会存储您在配置文件或成员资格或角色中存储的信息。 App_Data是此数据库的默认位置,但是当然可以更改它。尝试查找并更新web.config文件的部分,
<membership>
<providers>
</providers>
</membership>
了解详情,请查看以下帖子。
http://forums.asp.net/t/1517995.aspx