An Azure service that provides an event-driven serverless compute platform.
I think you would benefit from looking at this how-to guide, @Anonymous
Get connection info for dedicated sql pool
Quickstart: Use Python to query a database (generic)
connection-strings for Synapse SQL
Specifically, this excerpt, changed for making relevant to Synapse taken from example connection strings. Do note that other authentication options are available, such as Active Directory, integrated or password. You may need to add the Function to Synapse Access Control if you choose the Active Directory options.
import pyodbc
server = '<server>.sql.azuresynapse.net'
database = '<database>' # substitute pool name
username = '<username>'
password = '{<password>}'
driver= '{ODBC Driver 13 for SQL Server}' # or possibly 17 or 18 or {SQL Server Native Client 11.0}
with pyodbc.connect('DRIVER='+driver+';SERVER=tcp:'+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ password) as conn:
with conn.cursor() as cursor:
cursor.execute("SELECT TOP 3 name, location FROM mytable")
row = cursor.fetchone()
while row:
print (str(row[0]) + " " + str(row[1]))
row = cursor.fetchone()
While this is example code for illustrating usage, do note that credentials-in-code is terrible, bad, dangerous practice. It is recommended you have your Function get secrets from Key Vault.
Hope this will help. Please let us know if any further queries.
------------------------------
- Please don't forget to click on
or upvote
button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how - Want a reminder to come back and check responses? Here is how to subscribe to a notification
- If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators