PyODBC takes ~7 seconds to establish a connection with Azure SQL Server, is there a way to minimize this?
import os
import sys
import logging, logging.handlers
import getopt
import pyodbc
from database import *
# set up logging
logging.getLogger().setLevel(logging.INFO)
console = logging.StreamHandler()
console.setFormatter(logging.Formatter('%(asctime)s %(name)-12s %(levelname)s %(message)s'))
console.setLevel(logging.INFO)
logging.getLogger().addHandler(console)
logger = logging.getLogger("testapp")
def connect():
return pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
def purgeStoreData(conn, div_id, purge_days, lookback_days, store_start, store_end):
store_list = get_store_list(conn, div_id, store_start, store_end)
cursor = conn.cursor()
for store in store_list:
logger.info("Store %s ...", store)
cursor.execute("some query")
if __name__ == "__main__":
try:
conn = connect()
purgeStoreData(conn, DIV_ID, PURGE_DAYS, LOOKBACK_DAYS, STORE_START, STORE_END)
logger.info("*** Completed succesfully")
finally:
conn.close()
Is there a way to display the network latency ?