Azure Function Database Connection

血红的双手。 提交于 2020-04-18 05:42:12

问题


I have a Python package that I am able to run successfully on an Azure Data Science Virtual Machine. However, when I push it to Azure as a Function, I cannot successfully make a database connection. I was getting an error that the ODBC Driver 13 for SQL Server was not supported, so I changed the driver to ODBC Driver 17 for SQL Server and now I am NOT getting an error, but no data is being returned for a query that I know should return data.

Is there any other reason that data would not be returned? Firewall issues? do I need to add a binding? Do I need to separate out the connection string to feed each part (e.g., Driver, UID, PWD) into pyodbc.connect() separately? Right now I am feeding it in like this:

setting = os.environ("CONNECTIONSTRING")

conn = pyodbc.connect(setting)

This query works fine returning data when I run it on the VM using this code, just not as a Function.

(Note, this is different from my previous post regarding reading the Azure App Setting. That problem has been solved).


回答1:


There are many parts where this could be breaking.

I'd suggest start by having a Profiler or Extended Events trace on your SQL Server to verify whether a connection is even being established. If not then you need to work through the the various points of connectivity to find out where it breaks. The identity, firewall, NSGs etc might all come into play here.

Once you see a connection then you can play with permissions to ensure that your query then returns your data.

Without a full picture of your infrastructure and settings it is hard to pin it down further.




回答2:


Turns out it was not a database connectivity issue like I thought it was; it was a code error.



来源:https://stackoverflow.com/questions/60893887/azure-function-database-connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!