An Azure service that is used to automate, configure, and install updates across hybrid environments.
Hello Prajna !
Thank you for posting on MS Learn Q&A.
I think your issue is not from the SP because it fails before connecting to SQL Server and the Automation runbook cannot find the required ODBC Driver for SQL Server or the driver name in the connection string is wrong.
In the cloud sandbox uploading pyodbc/sqlalchemy is not enough because pyodbc also needs a native ODBC SQL Server driver installed on the machine. Azure Automation supports importing Python packages but native dependencies can be a limitation in the sandbox environment. Try to use a hybrid RW when the runbook needs local machine dependencies or specific network access. https://learn.microsoft.com/en-us/azure/automation/python-3-packages
check in your runbook
import pyodbc
print(pyodbc.drivers())
if you do not see something like:
ODBC Driver 17 for SQL Server
ODBC Driver 18 for SQL Server
then your connection will fail.
so run the python runbook on a HW and install:
Python
pyodbc
sqlalchemy
Microsoft ODBC Driver 17 or 18 for SQL Server
and use a DSN less connection string :
import pyodbc
conn = pyodbc.connect(
"DRIVER={ODBC Driver 18 for SQL Server};"
"SERVER=tcp:<server>.database.windows.net,1433;"
"DATABASE=<database>;"
"UID=<user>;"
"PWD=<password>;"
"Encrypt=yes;"
"TrustServerCertificate=no;"
)
cursor = conn.cursor()
cursor.execute("EXEC dbo.YourStoredProcedure")
conn.commit()