2010-03-11 140 views
4

我用aspnet_regsql创建了一个数据库,数据库是在sql sever 2008中创建的,而不是在我的项目中的数据文件夹中(我是否需要手动将它移动到文件夹?) 。
接下来,在网站管理工具中,我去了供应商部分,并点击了测试按钮。Asp.Net成员通过ASP.NET网站管理员工具

我得到了一个错误:

Could not establish a connection to the database. If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database, and then return to this tool to set the provider.

也许我需要设置一些在一个web.config,像会员设置或连接字符串(或ASP.NET网站管理员工具应该为我创造这些设置)?

更新:
也许这是因为我使用SQL Server 2008中完全不表达什么?

更新2:

成员设置部分和连接字符串在网站管理工具我aspnetdb的数据库后,我打开安全 - >安全设置WIZARD->定义角色(4期),我得到这个错误:

遇到错误。请返回上一页并重试。

The following message may help in diagnosing the problem: Unable to connect to SQL Server database. at System.Web.Administration.WebAdminPage.CallWebAdminHelperMethod(Boolean isMembership, String methodName, Object[] parameters, Type[] paramTypes) at ASP.security_wizard_wizardpermission_ascx.OnInit(EventArgs e) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

回答

0

打开SQL Management Studio并打开主数据库,使一个新的查询,并键入

sp_configure 'user instances enabled','1' 

执行此,然后键入

reconfigure 

,太执行此所以更改会影响。有关sp_configure的更多信息,如果您希望列出所有配置,则可以阅读http://msdn2.microsoft.com/en-us/library/ms188787.aspx,然后在没有任何参数的情况下执行sp_configure。

+0

我收到错误: 配置选项'启用用户实例'不存在,或者它可能是一个高级选项。 – luppi 2010-03-11 09:04:48

+0

您使用的是哪个版本的Sql服务器?以上仅适用于快递版本。 – bristows 2010-03-11 09:31:50

+0

请参阅我添加的更新... SQL Server 2008完整版... 如何使用完整版? – luppi 2010-03-11 09:34:14

5

是的,你需要修改web.config中的连接字符串。

查找在web.config中,你可能会看到这样的事情在<membership>元素:

<membership> 
    <providers> 
    <clear /> 
    <add connectionStringName="LocalSqlServer" 
     name="AspNetSqlMembershipProvider" 
     [...] 
     type="System.Web.Security.SqlMembershipProvider, 
       System.Web, 
       Version=2.0.0.0, 
       Culture=neutral, 
       PublicKeyToken=b03f5f7f11d50a3a" /> 
    </providers> 
</membership> 

connectionStringName属性告诉框架在<connectionStrings>元素来查找名为“LocalSqlServer连接字符串“ - 这可能不会在web.config中定义,因为它可以从.Net Frameworks核心config目录中的Machine.Config继承。

您应该为连接字符串选择一个新名称,并更新您的成员资格,角色和配置文件(如果您使用全部)提供程序以使用新名称。

然后在<connectionStrings>元素有以下几点:

<connectionStrings> 
    <remove name="LocalSqlServer" /> 
    <add name="MyConnectionString" 
     connectionString="Data Source=[ServerName];Initial Catalog=[DatabaseName];Integrated Security=True" 
     providerName="System.Data.SqlClient" /> 
</connectionStrings> 

调整值以满足您的系统 - 我建议集成安全性比在web.config中存储你的数据库登录名和密码,但情况因人而异(例如,在我的共享主机上,我不能使用集成安全性,所以必须提供用户/密码的详细信息)。

网站管理工具也会对这些连接字符串进行处理。

编辑回应置评

你有成功登录呢?或者创建了一个用户?我只是想排除你已经配置和连接连接字符串?

您是否已配置并开启角色提供程序?你有更新那里的“connectionStringName”属性吗?

请注意,如前所述,machine.config为您指定了一个默认角色提供程序,它试图指向本地SqlExpress实例 - 这可能是连接错误的来源。

<!-- Note enabled="true" - you need to turn this one on! --> 
<roleManager enabled="true"> 
    <providers> 
    <clear /> 
    <add connectionStringName="MyConnectionString" 
     [...] 
     type="System.Web.Security.SqlRoleProvider, 
       System.Web, 
       Version=2.0.0.0, 
       Culture=neutral, 
       PublicKeyToken=b03f5f7f11d50a3a" /> 
    </providers> 
</roleManager> 

有关消隐属性的更多详细信息,我建议你的文档:

一旦你已经配置了,应该所有的工作。

如果你没有能够创建一个用户/登录,我会检查:

  1. 连接字符串 - 确保名称匹配,确保data source您的服务器实例相匹配(不永远只是你机器的名字,可能是像“MachineName \ SqlServer”)。
  2. 如果您使用的是集成安全性,则需要确保您已为网站运行的帐户在数据库的适当权限下运行:您应该发现数据库中有多个角色,从aspnet_开始,为确保您可以创建用户(如果您有注册表单,您将需要),您应该将该帐户添加到aspnet_XXXX_FullAccess角色(每个角色用于成员资格,个性化,配置文件和角色)。
+0

我在web.config中没有部分,所以我手动创建了它,并且它工作正常。 现在我的问题:1)是否有一个选项可以自动生成 web.config中的设置,或仅手动生成? 2)我可以使用数据文件夹与本地数据库文件与SQL Server 2008充分? – luppi 2010-03-11 10:13:53

+0

请参阅更新2 – luppi 2010-03-11 10:30:11

+0

对不起,延迟应答,整天在开会。 – 2010-03-11 20:16:09

0

按照下面的步骤正确的会员集成到您的网站(如果你看到上面的错误,如

Could not establish a connection to the database. If you have not yet created the SQL Server database, exit the Web Site Administration tool, use the aspnet_regsql command-line utility to create and configure the database, and then return to this tool to set the provider”)。

第1步:

运行aspnet_regsql.exe的工具从C:\ WINDOWS \ Microsoft.NET \你的机器上框架\ V2.0.50727文件夹中。选择或双击aspnet_regsql.exe实用程序将打开如下所示的向导。

enter image description here

选择上面窗口下一步按钮会打开一个窗口,您可以配置SQL Server应用服务或从现有的数据库中删除应用程序服务的信息。

第2步:应用服务单选按钮

选择配置SQL Server安装新的数据库,然后选择下一步按钮。

enter image description here

步骤3

输入SQL Express服务器名,如下图所示。请注意,您可以将应用程序服务数据库名称更改为所需的名称(默认为aspnetdb)。(或)您可以选择Sql Server身份验证(用户名,密码,各自的数据库名称是必需的)

请注意,数据库ASPNETServices

enter image description here

第4步:

选择下一步按钮并确认您的设置是正确的与安装(在下面图像中显示)更进一步,选择下一步按钮。

enter image description here

步骤5

选择上面窗口下一步按钮成功安装应用程序服务数据库ASP.NET.Finally按完成后,将带您到确认窗口,如下所示。

enter image description here

步骤6

你会看到安装ASPNET服务数据库准备好你的ASP.NET应用程序中使用 enter image description here

0

我一直有类似的问题,因为这是我的第一次使用asp.net会员资格。如果您设置了<roleManager Enabled="False" />,您将能够完成创建用户。

我在这里猜测,但我认为AspNetSqlRoleProvider的web.config中有一个额外的提供者,并为它提供一个连接字符串,该连接字符串指向一个用户,该用户设置为访问角色管理信息SQL方面(查看sql用户的“此用户拥有的模式”和“数据库角色成员资格”的属性)将允许该工具正确进入数据库。

您在使用Windows身份验证或SQL身份验证的SQL Server上?

PS -

我越是阅读和理解Zhaph的回答,我越喜欢它。他给出了AspNetSqlRoleProvider元素的msdn模式的链接(不要被微软认为文档不存在,只需从“其他版本”下拉菜单中选择一个合适的版本)。

更新 我做了坏事在这里张贴实际测试什么,我在写之前,但我没有跟进并添加以下到Web.config让我既继续编辑的用户,并添加/管理角色。

<roleManager enabled="true"> 
    <providers> 
    <clear/> 
    <add name="AspNetSqlRoleProvider" 
     type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
     connectionStringName="MyConnectionString"/> 
    </providers> 
</roleManager> 

正如我前面提到的,除非你使用integrated security=true<identity impersonate="true" userName="windowsUser" password="winUsrPassword" />沿着我的连接字符串指定的用户所需的aspnet_Roles _...访问性能以及aspnet_Membership _...访问在这种情况下你的窗口用户需要这些属性。

相关问题