【问题标题】:Could not connect to database on ASP.NET Web Site Administration Tool无法连接到 ASP.NET 网站管理工具上的数据库
【发布时间】:2013-06-27 13:48:28
【问题描述】:

使用 ASP.NET 网站管理工具的正确流程是什么?我想使用这个工具来配置角色和成员资格。

我尝试过的步骤:

  1. 创建 MVC Web 应用程序。
  2. 运行 aspnet_regsql 创建相关数据库。下面的错误消息建议使用命令工具。虽然我知道 Role,但 Membership 表是在项目创建后创建的。
  3. 修改新web应用的web.config:

    <system.web>
    <roleManager enabled="true" defaultProvider="simple">
    <providers>
        <clear/>
        <add name="simple" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData"/>
    </providers>
    </roleManager>
    
    <membership defaultProvider="simple">
    <providers>
    <clear/>
    <add name="simple" type="WebMatrix.WebData.SimpleMembershipProvider,WebMatrix.WebData"/>
    </providers>
    </membership>
    ...
    ...
    <add name="DefaultConnection" connectionString="Data Source=(localdb)\.\IIS_DB;InitialCatalog=aspnet-DemoWebApplication-20130625124639;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnet-DemoWebApplication-20130625124639.mdf" providerName="System.Data.SqlClient" />
    

在工具页面上看到的错误消息: 您选择的数据存储存在问题。这可能是由无效的服务器名称或凭据或权限不足引起的。它也可能是由于未启用角色管理器功能造成的。单击下面的按钮可重定向到您可以选择新数据存储的页面。

以下消息可能有助于诊断问题:在调用“WebSecurity”类的任何其他方法之前,您必须调用“WebSecurity.InitializeDatabaseConnection”方法。此调用应放在站点根目录下的 _AppStart.cshtml 文件中。

你能帮忙吗?如果您需要更多信息,请告诉我。

我已经调查了这个问题几个小时,在下面有用的线程中找到了,但仍然没有完全解决它:

  1. Web Site Administration Tool ERRORS
  2. Web Site Administration Tool Not Working with ASP.NET MVC

【问题讨论】:

    标签: asp.net asp.net-membership role


    【解决方案1】:

    您的 Asp.net 应用程序中的连接字符串听起来不正确。

    如果需要,您可以直接在数据库中编写这些查询的脚本。

    检查您的 web.Config 文件并确保其中的所有连接都是正确的。您使用的是简单会员吗?还是 Asp.net 表?

    【讨论】:

    • 谢谢。我相信连接字符串是正确的,因为同样的事情在 mvc Web 应用程序中运行良好。我可以注册和登录。你是对的,我正在使用简单的membershp。现在我在调用“WebSecurity”类的任何其他方法之前关注这个错误“WebSecurity.InitializeDatabaseConnection”方法。这个调用应该放在一个_AppStart.cshtml中。我很困惑,因为没有这样的 _AppStart.cshtml。我在 global.asax.cs 中有一个电话:WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
    【解决方案2】:

    事实证明,MVC 4 附带的 SimpleMembership 不适用于网站管理工具。人们改用 WebSecutiry API。

    要将网站管理工具与 MVC 4/VS 2012 一起使用,您可以:

    1. 使用 MVC 3 应用程序,
    2. 使用 MVC 4 应用程序,基本模板 有了这两个选项,人们不需要修改web.config,不需要选择提供者。它只是工作。

    记得在使用网站管理工具之前构建网络应用程序。

    我指的是这个博客:http://weblogs.asp.net/jgalloway/archive/2012/08/29/simplemembership-membership-providers-universal-providers-and-the-new-asp-net-4-5-web-forms-and-asp-net-mvc-4-templates.aspx

    【讨论】:

      猜你喜欢
      • 2011-03-17
      • 1970-01-01
      • 1970-01-01
      • 2010-11-29
      • 1970-01-01
      • 2013-09-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多