Azure Web应用程序连接到SQL数据库随机错误

发布于 2025-01-24 12:07:05 字数 956 浏览 0 评论 0原文

我有一个需要连接到Azure SQL数据库的Azure Web应用程序。 我的测试方法是使用托管身份来验证Web应用程序。

因此,在我的Web应用程序中,我激活了托管身份,之后我登录了数据库并运行以下脚本:

CREATE USER [<identity-name>] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER [<identity-name>];
ALTER ROLE db_datawriter ADD MEMBER [<identity-name>];

保存并更新了数据库的连接字符串到我的Web应用程序中并重新启动。 一切都完美地工作了几个小时,之后我开始遇到此错误:

Microsoft.Data.SqlClient.SqlException (0x80131904): Login failed for user '<token-identified principal>'.
   at Microsoft.Data.ProviderBase.DbConnectionPool.CheckPoolBlockingPeriod(Exception e)
   at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)

这很让我感到困惑,因为在WB应用程序的重新启动后,我可以看到Web应用程序能够连接到数据库并检索数据。 。

这是以前发生的任何人吗?可以将我带到正确解决此问题的正确道路上?

不用说,我更新了我的EntityFramework和Data.sqlclient,以促进该方法如有记录。

非常感谢您提供的任何帮助

I have an azure web application running that need to connect to an Azure SQL Database.
My testing approach is to authenticate the web app by using Managed identity.

So in my web app I activated the managed identity, after that I logged into my database and run the following script:

CREATE USER [<identity-name>] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER [<identity-name>];
ALTER ROLE db_datawriter ADD MEMBER [<identity-name>];

Saved and updated the connection string of my database into my web app and restarted.
Everything worked perfectly for a couple of hours, after that I start getting this error:

Microsoft.Data.SqlClient.SqlException (0x80131904): Login failed for user '<token-identified principal>'.
   at Microsoft.Data.ProviderBase.DbConnectionPool.CheckPoolBlockingPeriod(Exception e)
   at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)

This is kind f confusing me because after the restart of the wb app, I can see that the web app is able to connect to the database and retrieve data..but suddenly after a couple of hours it starts throwing that error.

Did this occurred to anybody before and can direct me on the right path to solve this issue?

Goes without saying that I updated my Entityframework and Data.SqlClient to the correct version to facilitate this approach as documented.

Thank you so much for any help you can provide

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文