【问题标题】:how to change ASP.NET Configuration tool connection string如何更改 ASP.NET 配置工具连接字符串
【发布时间】:2011-06-06 09:52:34
【问题描述】:

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

我想使用我本地的 sql server 数据库而不是 sql express 来存储 Roles、Membership 和其他数据。

我已使用 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 高级版 项目类型为网站

【问题讨论】:

  • 谢谢,你解决了我的问题

标签: asp.net string configuration connection


【解决方案1】:

在查看 web.config 文件时无意中找到了我的问题答案。

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

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

在 web.config 中,您可以覆盖将使用的连接字符串名称:成员资格、个人资料和角色管理器。

覆盖会员使用:
<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>

【讨论】:

    猜你喜欢
    • 2012-01-23
    • 2021-12-18
    • 2014-02-24
    • 1970-01-01
    • 2012-12-31
    • 2019-04-13
    • 1970-01-01
    • 2021-01-09
    • 1970-01-01
    相关资源
    最近更新 更多