import pyodbc
server = '<server>.database.windows.net'
database = '<database>'
username = '<username>'
password = '<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 TOP 20 pc.Name as CategoryName, p.name as ProductName FROM [SalesLT].[ProductCategory] pc JOIN [SalesLT].[Product] p ON pc.productcategoryid = p.productcategoryid")
row = cursor.fetchone()
while row:
print (str(row[0]) + " " + str(row[1]))
row = cursor.fetchone()
I only see there is a username&&password credential to allow me to connect to Azure SQL database right now.
Is a way to let me connect to SQL database with Azure AD credential? e.g I want to use device_code_credentials
device_code_credentials = DeviceCodeCredential(client_id, tenant_id=tenant_id, authority=authority_host_uri)
I can call blob service client with this credential and wondering is there a simple way in Python SDK to connect to Azure SQL database.
blob_service_client = BlobServiceClient(
account_url=self.url,
credential=self.credential
)
