I am trying to connect to an Azure Synapse database through python code. I already have access to the database itself and can run queries using Azure Data Studio. However, the database connection fails specifying:
Error: (‘HY000’, ‘[HY000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Cannot open server “iberdrola.es” requested by the login. The login failed. (40532) (SQLDriverConnect); [HY000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Cannot open server “iberdrola.es” requested by the login. The login failed. (40532)’)
Below is the code i have used (wo passwords). The user and password is the same that works in the database itself. The ODBC controller is installed already. Any ideas why i am not allowed?
Thanks in advance,
Jon
import pyodbc
server = '*sql.azuresynapse.net'
database = 'D**l'
username = '***'
password = '***'
driver= '{ODBC Driver 13 for SQL Server}'
connection_string = f'DRIVER={driver};SERVER={server};DATABASE={database};UID={username};PWD= {password}'
with pyodbc.connect(connection_string) as conn:
with conn.cursor() as cursor:
cursor.execute("SELECT TOP 10 * FROM ***")
row = cursor.fetchone()
while row:
print (str(row[0]) + " " + str(row[1]))
row = cursor.fetchone()
My only purpose is to get proper connetion to the database through python to be able to run programs based on that Azure database.
user25188463 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.