Azure功能Python连接到Azure SQL DB

发布于 2025-01-24 02:42:00 字数 708 浏览 0 评论 0原文

我使用Python创建了一个Azure功能,并想将一些数据写入Azure SQL DB。
如果我通过AZ功能调试器在本地计算机上运行代码,则一切都在起作用。但是,当我将所有内容部署到Azure时,我只会收到一条错误(没有其他特定信息)。
我认为这与ODBC驱动程序有关吗? 我正在使用以下代码来连接和插入数据:

with pyodbc.connect('DRIVER='+driver+';SERVER=tcp:'+server+';PORT='+port+';DATABASE='+database+';UID='+username+';PWD='+ password + ";Authentication=ActiveDirectoryPassword", timeout=120) as conn:
        with conn.cursor() as cursor:
            try:
                cursor.execute(data)
            except:
                logging.error("Can't execute SQL Query!")             

我使用驱动程序='{odbc驱动程序17 for SQL Server}'作为驱动程序。
我认为这是Azure缺少的吗?该问题如何解决?通过Python连接从Azure函数到Azure SQL DB的正确方法是什么?

I created an Azure Function with Python and want to write some data into an Azure SQL DB.

If I run the code on my local machine via AZ Function Debugger, everything is working. But when I deploy everything to Azure, I only get a message that there is an error (no additional specific information).

I think this is related to the ODBC Driver?
I'm using the following code to connect and insert data:

with pyodbc.connect('DRIVER='+driver+';SERVER=tcp:'+server+';PORT='+port+';DATABASE='+database+';UID='+username+';PWD='+ password + ";Authentication=ActiveDirectoryPassword", timeout=120) as conn:
        with conn.cursor() as cursor:
            try:
                cursor.execute(data)
            except:
                logging.error("Can't execute SQL Query!")             

I use driver= '{ODBC Driver 17 for SQL Server}' as driver.

I assume that this is missing in Azure? How can this issue be fixed? What is the right approach to connect from Azure Functions to an Azure SQL DB via Python?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心意如水 2025-01-31 02:42:00

似乎包括ODBC驱动程序,只是库存不佳:

https:https:// github。 com/microsoftdocs/azure-docs/essess/54423

这里有一个示例项目:

https://github.com/kevin808/azure-function-pyodbc-mi

完整的教程,包括创建系统分配的身份的完整教程:

https:https:// /TechCommunity.microsoft.com/t5/apps-on-azure-blog/how-to-connect-azure-sql-database-from-python-function-function-app-using-ba-p/ba-p/3035595

有目前正在开发的SQL扩展名,但目前仅支持C#。 Python已被要求作为一种eHancement,因此您可以将您的

It seems the ODBC driver is included, it was just poorly documnented:

https://github.com/MicrosoftDocs/azure-docs/issues/54423

There is an example project here:

https://github.com/kevin808/azure-function-pyodbc-MI

The full tutorial including creating the system assigned identity can be found here:

https://techcommunity.microsoft.com/t5/apps-on-azure-blog/how-to-connect-azure-sql-database-from-python-function-app-using/ba-p/3035595

There is currently a SQL Extension under development but it only supports C# at the moment. Python has been requested as an ehancement so you could add your ???? to the issue so that you could use bindings

https://github.com/Azure/azure-functions-sql-extension/issues/172

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文