#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 |