2017-09-18 41 views
2

我在發佈到Azure服務器後嘗試重置密碼時收到此錯誤。但是,它適用於本地主機和所有其它功能像註冊,ConfirmEmail和登錄現場工作..等 錯誤:ResetPassword上的Asp.Net Identity 2.0無法連接到SQL Server數據庫。Azure web應用程序上的錯誤

Unable to connect to SQL Server database. Method Message:, LogException: System.Web.HttpException: Unable to connect to SQL Server database. ---> System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) 

在蔚藍我的連接字符串的樣子:

Server=tcp:server.database.windows.net,1433;Database=MyDb;User ID=username;Password=password;Trusted_Connection=False;Encrypt=True 

與選項Custom

+0

我不能在我身邊重現這個問題,'ChangePassword'功能在我的web應用程序中可以在本地和Azure上運行。你可以嘗試[遠程調試](https://docs.microsoft.com/en-us/azure/app-service-web/web-sites-dotnet-troubleshoot-visual-studio#remotedebug)你的網絡應用程序來檢查控制器動作''ChangePassword(ChangePasswordViewModel模型)''中'dbcontext'的連接。此外,如果可能的話,你可以分享你的項目,然後我可以測試你的代碼來找到問題。 –

+0

驗證您的Azure *服務器名稱*和*防火牆規則* – Jayendran

回答

0

我在發佈到Azure服務器後嘗試重置密碼時收到此錯誤。但是,它適用於本地主機和所有其它功能像註冊,ConfirmEmail和登錄..等錯誤帶電作業上:

Unable to connect to SQL Server database. 

所有功能/操作RegisterLoginRestPassword應該連接到同一個SQL Server數據庫,只有靜靜的密碼纔會返回錯誤,這很奇怪。我無法重現我的問題,請在本地使用Azure SQL數據庫爲您的應用程序指定連接字符串名稱,並在本地應用程序中執行RestPassword操作,並檢查它在本地是否仍然正常工作。

並請檢查是否的DbContext的數據庫連接字符串是要使用,如果數據庫訪問的一個。

public class ApplicationDbContext : IdentityDbContext<ApplicationUser> 
{ 
    public ApplicationDbContext() 
     : base("DefaultConnection", throwIfV1Schema: false) 
    { 

    } 

    public static ApplicationDbContext Create() 
    { 
     return new ApplicationDbContext(); 
    } 
} 

此外,正如我在評論中提到,你可以嘗試remote debug your web app檢查的DbContext的控制器動作實際連接,並確保如果這些RegisterLoginRestPassword操作連接到相同的SQL Server數據庫。

相關問題