resetpassword上的ASP.NET Identity 2.0无法连接到Azure Web应用程序上的SQL S



我在发布到Azure Server后尝试重置密码时收到了此错误。但是,它在Localhost上起作用,所有其他功能都在实时工作,例如注册,确认书和登录。错误:

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)

我在Azure中的连接字符串看起来像:

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

使用选项Custom

发布到Azure服务器后尝试重置密码时,我收到了此错误。但是,它可以在Localhost上工作,所有其他功能都在实时工作,例如注册,确认书和登录。等等。错误:

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

此外,正如我在评论中提到的那样,您可以尝试远程调试您的Web应用程序,以检查Controler Action中DBContext的实际连接,并确保这些RegisterLoginRestPassword操作是否连接到同一SQL Server数据库。

最新更新