ResetPassword上的Asp.Net Identity 2.0无法连接到SQL Server数据库。Azure web应用程序上的错误

问题描述:

我在发布到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

我在发布到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数据库。