I am trying to connect to azure sql database. But somehow I keep getting the following error:
pyodbc.OperationalError: ('08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]Client unable to establish connection (0) (SQLDriverConnect)')
I have ODBC Driver 17 installed.
here is my code:
import pyodbc
server = 'mftaccountinghost.database.windows.net'
database = 'mft_accounting'
username = 'localhost'
password = '######'
driver= '{ODBC Driver 17 for SQL Server}'
cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
cursor.execute("select * from dbo.expense_zoho")
row = cursor.fetchone()
while row:
print (str(row[0]) + " " + str(row[1]))
row = cursor.fetchone()
Here is my connection string on Azure SQL Database
Does anyone have an idea why the error pops up?
Thanks.
Encrypt=yes
when you build it in your Python code? – Gord Thompson