2015-11-19 59 views
0

我正在將網站和數據庫從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異常,布爾breakConnection,行動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重試,DbConnectionOptions USEROPTIONS,DbConnectionInternal &連接) 的系統。 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 retry,DbConnectionOptions userOptions) at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) at System.Data.SqlClient。 SqlConnection.Open() at System.Web.DataAccess.SqlConnectionHolder.Open(HttpContext context,Boolean revertImpersonate) at System.Web.DataAccess.SqlConnectionHelper.GetConnection(String connectionString,Boolean revertImpersonation) at System.Web.Security.SqlMembershipProvider .GetPasswordWithFormat(字符串username,布爾updateLastLoginActivityDate,的Int32 &狀態,字符串&密碼,的Int32 &了passwordFormat,字符串& passwordSalt,的Int32 & failedPasswordAttemptCount,的Int32 & failedPasswordAnswerAttemptCount,布爾& isApproved,日期時間& lastLoginDate,日期時間& lastActivityDate) 在System.Web.Security.SqlMembershipProvider.CheckPassword(字符串username,字符串密碼,布爾updateLastLoginActivityDate,布爾failIfNotApproved,字符串&鹽,的Int32 &了passwordFormat) 在System.Web.Security.SqlMembershipProvider.ValidateUser(字符串username,字符串密碼) 在EbpWebSite.Account.login.Page_PreLoad(對象發件人,EventArgs的) 在System.Web.UI.Page.ProcessRequestMain(布爾includeStagesBeforeAsyncPoint,布爾includeStagesAfterAsyncPoint)

我缺少的東西?這一舉措是否搞砸了登錄密碼鹽?我的登錄表是標準的aspnet_Membership,Roles,Users設置。我只是從Azure複製到本地數據庫。第一行會顯示,我的連接字符串已正確更新。

由於建議增加的ConnectionString

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

原始字符串是服務器= 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("[email protected]"); 
      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); 
    } 

被叫公用事業類:

 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; 
    } 

回答

0

有時它是簡單的事情。網站和數據庫都駐留在同一臺物理服務器上,因此將連接字符串更改爲

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

它工作。

0

可以從網絡發佈的ConnectionStrings標籤。 config文件,以及您的code_behind(您連接到數據庫的位置)?我從來沒有tryed使用標準的認證,但我懷疑它使用了一些面向服務器的功能(如你所說,你移動到蔚藍的服務器後,錯誤已顯示)

+0

加入,並動過天青後發生的錯誤。它工作得很好,只是沒有本地。 – alemus

+0

我從來沒有類似的情況因爲我從來沒有使用過Azure ......對不起 – Khazratbek

相關問題