如何更改ASP.NET配置工具连接字符串

Zvi*_*adi 4 asp.net string connection configuration

如何更改ASP.NET配置工具的连接字符串名称?(ASP.NET配置工具将使用哪个连接字符串)我正在学习ASP.NET和所有地方以及我现在正在阅读的书中的连接字符串名为:LocalSqlServer.

我想使用我的本地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 Premium项目类型是网站

Zvi*_*adi 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>