File size: 695 Bytes
28aefca 74ac7c0 28aefca 74ac7c0 28aefca 74ac7c0 28aefca 74ac7c0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#db_connection.py
import os
from azure.identity import ClientSecretCredential
import pymssql
def get_db_connection():
server = 'aideatexdb.database.windows.net'
database = 'textdb'
client_id = os.getenv('AZURE_CLIENT_ID')
client_secret = os.getenv('AZURE_CLIENT_SECRET')
tenant_id = os.getenv('AZURE_TENANT_ID')
credential = ClientSecretCredential(tenant_id, client_id, client_secret)
token = credential.get_token("https://database.windows.net/.default")
conn = pymssql.connect(server=server,
database=database,
user=client_id+'@'+server,
password=token.token)
return conn |