connect to azure sql database from python

Solutions on MaxInterview for connect to azure sql database from python by the best coders in the world

showing results for - "connect to azure sql database from python"
Giuseppe
12 Feb 2017
1import pyodbc
2server = '<server>.database.windows.net'
3database = '<database>'
4username = '<username>'
5password = '<password>'   
6driver= '{ODBC Driver 17 for SQL Server}'
7
8with pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ password) as conn:
9    with conn.cursor() as cursor:
10    	# code...
11        # ex: cursor.execute("SELECT TOP 3 name, collation_name FROM sys.databases")
12