移动数据库和网站

时间:2015-11-19 23:10:23

标签: asp.net asp.net-membership

我正在将网站和数据库从azure重定位到本地服务器(sql server 2008 r2)。 我成功复制了数据库并在IIS中设置了网站。我可以很好地导航到网站,但它不会登录。

我的堆栈跟踪

Message: A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The target principal name is incorrect.)

堆栈跟踪:在System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,Boolean breakConnection,Action 1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParserStateObject.SNIWritePacket(SNIHandle handle, SNIPacket packet, UInt32& sniError, Boolean canAccumulate, Boolean callerHasConnectionLock) at System.Data.SqlClient.TdsParserStateObject.WriteSni(Boolean canAccumulate) at System.Data.SqlClient.TdsParserStateObject.WritePacket(Byte flushMode, Boolean canAccumulate) at System.Data.SqlClient.TdsParser.TdsLogin(SqlLogin rec) at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnectionOptions userOptions) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource 1 retry,DbConnectionOptions userOptions,DbConnectionInternal& connection)    在System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,TaskCompletionSource 1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource 1重试,DbConnectionOptions userOptions)    在System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1重试)    在System.Data.SqlClient.SqlConnection.Open()    在System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context,Boolean revertImpersonate)    在System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString,Boolean revertImpersonation)    在System.Web.Security.SqlMembershipProvider.GetPasswordWithFormat(String username,Boolean updateLastLoginActivityDate,Int32& status,String& password,Int32& passwordFormat,String& passwordSalt,Int32& failedPasswordAttemptCount,Int32& failedPasswordAnswerAttemptCount,Boolean& isApproved,DateTime& lastLoginDate,DateTime& ; lastActivityDate)    at System.Web.Security.SqlMembershipProvider.CheckPassword(String username,String password,Boolean updateLastLoginActivityDate,Boolean failIfNotApproved,String& salt,Int32& passwordFormat)    at System.Web.Security.SqlMembershipProvider.ValidateUser(String username,String password)    在EbpWebSite.Account.login.Page_PreLoad(Object sender,EventArgs e)    在System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)

我错过了什么吗?移动是否搞砸了登录的密码盐?我的登录表是标准的aspnet_Membership,角色,用户设置。我刚刚从Azure复制到本地数据库。第一行表示,我正确更新了连接字符串。

建议添加connectionString

<add name="EbpCloud" connectionString="Server=EBP-OCON-SQL1;User ID=dbread22;Password=*****;Trusted_Connection=True;Encrypt=True;Connect Timeout=0;Database=EbpReporting;" />

原始字符串是Server = tcp:server.database.windows.net

该网站位于与数据库相同的服务器上。 (我是否需要将本地作为服务器名称的一部分?) 我的登录代码:

      if (Membership.ValidateUser(userName, passWord)) {
    FormsAuthentication.Initialize();
    FormsAuthentication.SetAuthCookie(userName, false);
    using (var conn = Utilities.SqlConnectionEbp(Utilities.DatabaseEbp.EbpReporting)) {
      // call stored procedure to get the user default session settings
      using (var cmd = new SqlCommand("aspnet_UserDefaultSessionSettings", conn)) {
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add(new SqlParameter("@UserName", userName));
        // Check Sql State and open connection
        if (!conn.State.Equals(ConnectionState.Open))
          conn.Open();
        using (var reader = cmd.ExecuteReader()) {
          while (reader.Read()) {
            Session["userName"] = userName;
            Session["forceResetPassword"] = passWord.Equals("p@ssw0rd");
            Session["displayName"] = reader["displayName"].ToString();
            Session["instanceId"] = Convert.ToInt16(reader["instanceId"]);
            Session["userEmail"] = reader["email"].ToString();
            Session["userId"] = new Guid(reader["UserId"].ToString());
            //Session["clinicList"] = Utilities.GetClinicList();
          }
        }
      }
    }
    Response.Redirect("/administration/supplierinvoice.aspx", false);
  }

名为Utilities的课程:

      public static class Utilities
  {
    public enum DatabaseEbp
    {
      Ebp, EbpReporting, Master, ebpCIS
    }
    /// <summary>
    /// SqlConnectionEBP - EBP Connection object
    /// </summary>
    /// <returns>SqlConnection</returns>
    public static SqlConnection SqlConnectionEbp(DatabaseEbp database) {
      var connString = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["EbpCloud"].ToString());
      connString.InitialCatalog = database.ToString();
      var conn = new SqlConnection(connString.ToString());
      return conn;
    }

2 个答案:

答案 0 :(得分:0)

您可以从 web.config 文件和code_behind(连接到数据库的位置)发布 connectionStrings 标记吗?我从未尝试使用标准身份验证,但我怀疑它使用了一些面向服务器的功能(正如您所说的,在移动到azure服务器后显示错误)

答案 1 :(得分:0)

有时这是简单的事情。网站和数据库都位于同一物理服务器上,因此将连接字符串更改为

  <add name="EbpCloud" connectionString="Data Source=localhost;Initial Catalog=ebpreporting;Persist Security Info=True;User ID=dbread22;Password=*****" providerName="System.Data.SqlClient" />

并且有效。