且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Azure SQL数据库上调试“用户登录失败"?

更新时间:2021-08-12 08:07:45

该错误似乎可以连接到服务器,但服务器拒绝登录.服务器日志中的调试会有所帮助,因此您正在寻找正确的位置.

The error looks like you are able to connect to the server but the server rejects the login. Debugging in the server logs would help, so you are looking at the right place.

您可以启用Azure SQL数据库审核&对待检测.您可以通过打开SQL Server资源并选择安全性"/审核和测试"来在SQL Server实例级别启用它.对待检测.选择一个存储帐户以在存储详细信息"中存储日志(请参见下图).有关更多信息,请参见 https://docs.microsoft. com/en-us/azure/sql-database/sql-database-auditing .

You can enable Azure SQL Database Auditing & Treat Detection. You can enable it on SQL Server instance level by opening your SQL Server resource and selecting Security / Auditing & Treat Detection. Select a storage account to store logs in Storage details (see picture below). For more information, see https://docs.microsoft.com/en-us/azure/sql-database/sql-database-auditing.

启用审核后,尝试登录到数据库.之后,您可以在名为 sqldbauditlogs 的Blob容器中的指定Azure存储帐户中找到日志.日志位于具有xel扩展名的文件中的/servername/databasename/SqlDbAuditing_ServerAudit_NoRetention/yyyy-mm-dd/文件夹中.您可以下载并在SSMS中打开.xel文件(文件/打开/文件…). xel文件包含事件,您可以在那里查看登录尝试.

After enabling auditing try to login to your database. After that you can find the logs in the specified Azure Storage Account in blob container named sqldbauditlogs. The logs are in folder /servername/databasename/SqlDbAuditing_ServerAudit_NoRetention/yyyy-mm-dd/ in files with xel extension. You can download and open the .xel -file in SSMS (File / Open / File…). The xel file contains events and you can see login attempts there.

事件字段成功指示登录是否失败,并且字段 server_principal_name 都包含用户名. 从字段 additional_information 中的文本中,您可以找到error_code(在xml中).错误代码40615被防火墙阻止,代码18456用户名或密码错误. (错误代码来自 https://docs .microsoft.com/en-us/azure/sql-database/sql-database-develop-error-messages )

Event field succeeded tells if the login failed or not, and field server_principal_name contains the username in both cases. From text in field additional_information you can find error_code (in the xml). Error code 40615 is blocked by firewall and code 18456 is wrong username or password. (error codes from https://docs.microsoft.com/en-us/azure/sql-database/sql-database-develop-error-messages)

您还可以在数据库系统表中找到一些信息以分析连接,例如sys.event_log(请参阅:

You can also find some information in the database system tables for analysing the connections, e.g. sys.event_log (see: https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-event-log-azure-sql-database?view=azuresqldb-current).

可以在以下位置找到有关对Azure SQL数据库连接进行故障排除的更多信息:

More information on troubleshooting the Azure SQL Database connectivity can be found here: https://docs.microsoft.com/en-us/azure/sql-database/sql-database-troubleshoot-common-connection-issues.

我希望这可以帮助您调试连接.

I hope this helps you forward with debugging the connection.