【发布时间】:2020-11-02 23:14:17
【问题描述】:
我正在尝试使用带有令牌身份验证的 pyodbc.connect() 从 Azure 函数连接到 Azure SQL。 Azure SQL DB 已配置自动暂停。如果我在 SQL 数据库“暂停”后调用 Azure 函数,第一次尝试总是失败。
我尝试使用 timeout=60 将 timeout 参数添加到 pyodbc.connect(),但我仍然遇到错误,例如:
('HY000', "[HY000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Database '<DB_NAME>' on server
'<SERVER_NAME>.database.windows.net' is not currently available. Please retry the connection later. If
the problem persists, contact customer support, and provide them the session tracing ID of
'{<TRACKING_ID>}'. (40613) (SQLDriverConnect)")
如何确保我对 Azure SQL 的第一次调用不会失败?
【问题讨论】:
-
如您所说,如果您的数据库被暂停,我们将无法访问它!
-
我们无法确保您对 Azure SQL 的第一次调用不会失败,因为数据库已暂停。
-
我想这是有道理的。那么最初发送连接请求以唤醒 SQL DB(可能在 Azure 函数之外)的解决方案,让剩余的 Azure 函数代码在没有连接问题的情况下运行吗?
-
是的,您应该在 Azure Function 运行之前让数据库恢复。
标签: azure-functions azure-sql-database pyodbc