Hi @Anonymous ,
Thank you for posting query in Microsoft Q&A Platform.
You should use
pyodbc
library to do the same. Click here to know more about pyodbc library.
Please check below screenshot where I tried to execute Stored procedure from Synapse notebook.
import pyodbc
server = '<yourDbServerName>'
database = '<yourDBName>'
username = '<UserName>'
password = '<Password>'
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=' + server + ';DATABASE='+ database +';UID=' + username + ';PWD='+ password)
cnxn.execute('EXEC spInsertEmp')
cnxn.commit()
cnxn.close()
You can also consider using Synapse pipeline for this. You can execute your notebook using Synapse notebook activity and then execute Stored procedure activity to run your stored procedure.
Hope this helps. Please let us know if any further queries.
Please consider hitting Accept Answer
button. Accepted answers help community as well.