简体   繁体   English

SetPropertyValue期间发生CreateUserWizard错误:无法连接到SQL Server数据库

[英]CreateUserWizard error during SetPropertyValue: Unable to connect to SQL Server database

I have a ASP.NET Application which normally can connect Database,can create users using CreateUserWizard but starting using profiles i stuck to below exception during user profile update: 我有一个ASP.NET应用程序,该应用程序通常可以连接数据库,可以使用CreateUserWizard创建用户,但是开始使用我在用户配置文件更新期间遇到以下异常的配置文件:

[SqlException (0x80131904): Login failed for user 'My-PC\\User'.] [SqlException(0x80131904):用户'My-PC \\ User'的登录失败。
[HttpException (0x80004005): Unable to connect to SQL Server database.] [HttpException(0x80004005):无法连接到SQL Server数据库。

I'm sure about below items: 我确定以下项目:

  1. Connection string is ok and app can access db 连接字符串正常,应用程序可以访问数据库
  2. User are created using CreateUserWizard in database with no error if i don't want to update their profile 用户正在使用的CreateUserWizard在数据库中创建的,并没有错误,如果我不想更新他们的个人资料

Only when I want to call this.SetPropertyValue("FirstName", value); 仅当我想调用this.SetPropertyValue("FirstName", value); everything go wrong and below error shown: 一切都会出错,并且显示以下错误:

SQLExpress database file auto-creation error: SQLExpress数据库文件自动创建错误:

The connection string specifies a local Sql Server Express instance using a database location within the application's App_Data directory. 连接字符串使用应用程序的App_Data目录中的数据库位置指定本地Sql Server Express实例。 The provider attempted to automatically create the application services database because the provider determined that the database does not exist. 提供者尝试自动创建应用程序服务数据库,因为提供者确定该数据库不存在。 The following configuration requirements are necessary to successfully check for existence of the application services database and automatically create the application services database: 要成功检查应用程序服务数据库的存在并自动创建应用程序服务数据库,必须满足以下配置要求:

If the application is running on either Windows 7 or Windows Server 2008R2, special configuration steps are necessary to enable automatic creation of the provider database. 如果应用程序在Windows 7或Windows Server 2008R2上运行,则必须执行特殊的配置步骤才能启用提供程序数据库的自动创建。 Additional information is available at: http://go.microsoft.com/fwlink/?LinkId=160102 . 有关其他信息,请访问: http : //go.microsoft.com/fwlink/?LinkId=160102 If the application's App_Data directory does not already exist, the web server account must have read and write access to the application's directory. 如果应用程序的App_Data目录不存在,则Web服务器帐户必须具有对该应用程序目录的读写权限。 This is necessary because the web server account will automatically create the App_Data directory if it does not already exist. 这是必需的,因为如果Web服务器帐户尚不存在,它将自动创建App_Data目录。

If the application's App_Data directory already exists, the web server account only requires read and write access to the application's App_Data directory. 如果应用程序的App_Data目录已经存在,则Web服务器帐户仅需要对应用程序的App_Data目录的读写权限。 This is necessary because the web server account will attempt to verify that the Sql Server Express database already exists within the application's App_Data directory. 这是必需的,因为Web服务器帐户将尝试验证应用程序的App_Data目录中是否已存在Sql Server Express数据库。 Revoking read access on the App_Data directory from the web server account will prevent the provider from correctly determining if the Sql Server Express database already exists. 从Web服务器帐户撤消对App_Data目录的读取访问权限,将阻止提供程序正确确定Sql Server Express数据库是否已存在。 This will cause an error when the provider attempts to create a duplicate of an already existing database. 当提供程序尝试创建已经存在的数据库的副本时,这将导致错误。 Write access is required because the web server account's credentials are used when creating the new database. 由于创建新数据库时会使用Web服务器帐户的凭据,因此需要写访问权限。

Sql Server Express must be installed on the machine. 必须在计算机上安装Sql Server Express。
The process identity for the web server account must have a local user profile. Web服务器帐户的进程标识必须具有本地用户配置文件。 See the readme document for details on how to create a local user profile for both machine and domain accounts. 有关如何为计算机帐户和域帐户创建本地用户配置文件的详细信息,请参见自述文档。

Here is web.config : 这是web.config

<configuration>
  <connectionStrings>
    <add name="MUQ_SMSConnectionString" 
         connectionString="Data Source=MY-PC\SQLEXPRESS12SP1;Initial Catalog=MyDB;" 
         providerName="System.Data.SqlClient;Integrated Security=True"/>
  </connectionStrings>
  ............
</configuration>

Here is profile update method: 这是配置文件更新方法:

protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
{
    ProfileCommon userProfile = (ProfileCommon)ProfileCommon.Create(CreateUserWizard1.UserName, true);
    userProfile.FirstName = textBoxFirstName.Text.Trim();
    userProfile.LastName = textBoxLastName.Text.Trim();
    userProfile.MobileNumber = textBoxUserName.Text.Trim();

    if (radioButtonMaleGender.Checked == true)
        userProfile.Gender = MALE_GENDER_TAG;
    else if (radioButtonFemaleGender.Checked == true)
        userProfile.Gender = FEMALE_GENDER_TAG;
    else
        userProfile.Gender = UNKNOW_GENDER_TAG;

    userProfile.Save();
}

Here is the definition of profile and overriding of default provider: 这是配置文件的定义和默认提供程序的覆盖:

<membership defaultProvider="MySqlProvider" >
      <providers>
        <add name="MySqlProvider"
             type="System.Web.Security.SqlMembershipProvider"
             applicationName="/"
             connectionStringName="MUQ_SMSConnectionString"
              requiresUniqueEmail="False"
             requiresQuestionAndAnswer="false" />
      </providers>
    </membership>
    <anonymousIdentification enabled="true" />

    <profile enabled="true">
      <properties>
        <add name="MobileNumber" type="string" allowAnonymous="true"/>
        <add name="FirstName" type="string" allowAnonymous="true"/>
        <add name="LastName" type="string" allowAnonymous="true"/>
        <add name="Gender" type="string" allowAnonymous="true"/>
      </properties>
    </profile>
    <roleManager enabled="true"/>

Note: I have another problem which I suspect that it may be related to this error. 注意:我还有另一个问题,我怀疑这可能与此错误有关。 When I want to edit security options of app in Administration Panel of Application, SQL Server crashes and report for errors in windows. 当我想在应用程序的管理面板中编辑应用程序的安全选项时,SQL Server崩溃并报告Windows中的错误。

Currently I'm using SQL Server 2012SP1 Express on Windows 8.1. 当前,我在Windows 8.1上使用SQL Server 2012SP1 Express。 I had SQL Server 2008 R2 Express and then installed 2012 Express but nothing changed. 我安装了SQL Server 2008 R2 Express,然后安装了2012 Express,但未进行任何更改。

When you use the AspDotNetProfile provider without providing a provider configuration in your web.config file, you are using the provider configuration in your machine.config file. 当您使用AspDotNetProfile提供程序但未在web.config文件中提供提供程序配置时,您正在使用machine.config文件中的提供程序配置。 Here's a sample from the default machine.config file distributed with .NET 4.0: 这是随.NET 4.0一起分发的默认machine.config文件的示例:

    <profile>
        <providers>
            <add name="AspNetSqlProfileProvider" connectionStringName="LocalSqlServer" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
        </providers>
    </profile>

The connection string that is referenced in this definition can also be found in machine.config: 该定义中引用的连接字符串也可以在machine.config中找到:

<connectionStrings>
    <add name="LocalSqlServer" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
</connectionStrings>

It appears from your question that you haven't overrided the default profile definition in your web.config. 从您的问题看来,您尚未覆盖web.config中的默认配置文件定义。 So, what's happening is that the profile provider is looking for a SQL Server Express instance named SQLEXPRESS on the local machine. 因此,正在发生的情况是,配置文件提供程序正在本地计算机上查找名为SQLEXPRESS的SQL Server Express实例。 The reason is must be an Express instance is because User instances (see docs for AttachDBFilename) are only supported on the Express edition. 原因必须是Express实例,因为仅Express版本支持用户实例(请参阅docs中的AttachDBFilename)。

So, you have two choices: 1. Override the default provider configuration. 因此,您有两个选择:1.覆盖默认的提供程序配置。 this can be done by removing the default configuration and re-adding a configuration with the same name. 这可以通过删除默认配置并重新添加具有相同名称的配置来完成。 2. Set up a SQL Server Express instance with the default instance name on your web server. 2.在您的Web服务器上使用默认实例名称设置一个SQL Server Express实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM