【问题标题】:Web Site Administration Tool: The connection name 'LocalSqlServer' was not found in the applications configuration or the connection string is empty网站管理工具:在应用程序配置中未找到连接名称“LocalSqlServer”或连接字符串为空
【发布时间】:2012-10-07 20:13:44
【问题描述】:

我正在尝试使用网站管理工具为我的服务器上的网站配置成员资格。我已经在我的本地 SQL Server 副本上创建了一个 aspnetdb 数据库,并且通过 WSAT,我设法添加了几个角色,并锁定了服务器上的几个目录。

但是,当我尝试管理用户时,出现以下错误:

在应用程序配置中找不到连接名称“LocalSqlServer”或连接字符串为空。在 System.Web.Util.SecUtility.GetConnectionString(NameValueCollection config) 在 System.Web.Security.SqlMembershipProvider.Initialize(String name, NameValueCollection config) 在 System.Web.Configuration.ProvidersHelper.InstantiateProvider(ProviderSettings providerSettings, Type providerType)

显然,LocalSqlServer 连接字符串 OK,否则我将无法添加角色,例如。

web.config相关部分如下:

  <connectionStrings>
        <clear />
        <remove name="LocalSqlServer"/>
        <add name="LocalSqlServer" connectionString="Data Source=(local);Initial Catalog=aspnetdb;User Id=LoginUser;Password=password;" providerName="System.Data.SqlClient"/>
  </connectionStrings>

  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880" defaultUrl="~/admin/admin.aspx" />
    </authentication>
        <membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
            <providers>
                <clear />
                <add
          name="SqlProvider"
          type="System.Web.Security.SqlMembershipProvider"
          connectionStringName="LocalSqlServer"
          applicationName="myapp" />
            </providers>
        </membership>
    <profile>
      <providers>
        <clear />
                <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="myapp" />
      </providers>
    </profile>
    <roleManager enabled="true">
      <providers>
        <clear />
                <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="LocalSqlServer" applicationName="myapp" />
      </providers>
    </roleManager>
  </system.web>

据我了解,清除/删除元素应该覆盖任何其他配置文件,但无论如何,我尝试将相同的连接字符串添加到相关的 machine.config,但无济于事。

有什么想法吗?

作为替代方案,我是否有任何理由不能直接调用 Membership DB 存储过程?有人知道任何支持文件吗?

【问题讨论】:

  • 您还没有找到任何解决方案?
  • @ForceMagic - 抱歉,这是一个非工作时间项目。感谢您的回复-我希望明天能再破解一次。我会尽快回复。

标签: sql-server-2008 asp.net-membership website-admin-tool


【解决方案1】:

经过一些研究,我为您找到了可能的解决方案。我想您可能已经阅读了我找到的一些帖子,但我试图指出与您向我们展示的版本的不同之处。

在角色管理器标签中,

您尚未设置可能导致问题的defaultProvider

<roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider">

请参阅this link 了解更多详情。这也是我的参考。

我也注意到了

connectionString 中,User ID 的“d”不是大写字母。不确定是否区分大小写。

而且,有些线程似乎根据自己的需要设置了Integrated Security=,在connectionString,你可以尝试这样做。

this link

显然,

默认情况下,成员资格/角色提供程序使用“localSQLServer” [...] 设置为指向本地 SQL Express 的连接字符串 来自根 web.config 的数据库。大多数情况下,服务器不会 安装了 SQL express,你会得到这个错误。

通过清除连接字符串应该可以发现这些错误。

Reference

但我相信您已经在各处使用&lt;/clear&gt; 标签,这是正确的。

更多参考资料

您可能还想看看aspnet Forums,因为这是他们的技术。我输入了你的错误信息,实际上得到了很多结果。

终于

如果这些建议中的任何一个都没有解决您的问题,我建议您“从头开始”重新开始,逐个添加每个配置。祝你好运!

【讨论】:

  • 我想知道 defaultRoleProvider 是否可能是问题所在,但遗憾的是事实并非如此。但是感谢您的想法。
  • @CJM 好的,好吧,当你找到它时不要忘记更新线程。问候
【解决方案2】:

我尽可能多地放弃了最初的尝试,然后重新开始。这一次我创建了一个新的、单独的会员数据库,并从 machine.config 中注释掉了所有角色和会员提供者元素...

这并没有解决问题,但在此过程中,我意识到即使我修改了 machine.config,WSAT 仍会从某处获取角色提供程序配置。这导致我点击了 x86 machine.config,这反过来又让我回到了应用程序池——应用程序池被设置为启用 32 位应用程序。

将此重置为 false 使我能够克服我的错误,尽管改为不同的错误 - 但是,我将单独调查此问题并在必要时创建一个新帖子。

我不确定为什么 32 位应用程序池会导致问题 - 我仍然希望我的 web.config(带有 &lt;clear /&gt; 项)应该替换从机器继承的所有适当设置。 config - 无论是哪个版本。因此,我的“重建”的其他部分可能也做出了贡献;很难说。

恐怕不是我希望的最终解决方案。

【讨论】:

    【解决方案3】:

    这对我有用:

    1. 在 Visual Studio 中,转到服务器资源管理器并附加 aspnetdb
    2. 右键单击aspnetdb - 修改连接
    3. 如果连接测试有效,请单击“高级”并在窗口按钮处复制连接字符串
    4. 在您的 web.config/ConnectionStrings/ApplicationServices/ConnectionString 中替换此连接字符串

    【讨论】:

      猜你喜欢
      • 2012-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-02
      • 1970-01-01
      • 2012-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多