2011-01-10 71 views
4

如何更改ASP.NET配置工具连接字符串名称? (ASP.NET配置工具将使用哪个连接字符串) 我正在学习ASP.NET和无处不在以及我正在阅读的书中,现在读取了名为LocalSqlServer的连接字符串。如何更改ASP.NET配置工具连接字符串

我想用我的本地sql server数据库而不是sql express来存储角色,成员和其他数据。

我已经使用aspnet_regsql.exe在我的数据库中创建所需的数据结构。之后,我改变了我的web.config看起来像:

<connectionStrings> <remove name="LocalSqlServer"/> <add name="LocalSqlServer" connectionString="Server=(LOCAL); Database=MyDatabase;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings>

但是当我运行ASP.NET配置工具,它说: “连接名称‘ApplicationServices’在应用程序的配置没有被发现或连接字符串是空的。“

ASP.NET配置工具使用名为ApplicationServices而不是LocalSqlServer的连接字符串。

原因,我必须修改web.config中: <connectionStrings> <add name="ApplicationServices" connectionString="Server=(LOCAL); Database=MyDatabase;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings>

,一切工作正常。

我想知道为什么我的网站使用连接字符串命名为:ApplicationServices和所有书籍和在线文档使用LocalSqlServer?以及如何将其更改为LocalSqlServer?

我: 的Windows 7 的Sql Server 2008 R2的 Visual Studio 2010的溢价 项目类型网站

+0

感谢,你解决了我的问题 – 2016-03-29 10:41:49

回答

15

无意中我发现我的问题的答案寻找web.config文件时。

如果您覆盖web.config文件中的默认machine.config配置设置,则可以更改ASP.NET配置工具的连接字符串名称。

我从book-s代码归档中获得了我的web.config文件,这是问题所在。

在web.config中,你可以重载将使用哪个连接字符串名称:membership,profile和roleManager。

重写成员使用:
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="LocalSqlServer"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="/"/>
</providers>
</membership>

其中的connectionStringName是将被用于存储数据成员的连接字符串的名称。

别人:

<profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider"
type="System.Web.Profile.SqlProfileProvider"
connectionStringName="LocalSqlServer"
applicationName="/"/>
</providers>
</profile>

<roleManager enabled="true">
<providers>
<clear />
<add connectionStringName="LocalSqlServer" applicationName="/"
name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
<add applicationName="/" name="AspNetWindowsTokenRoleProvider"
type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>
</roleManager>