conn_string = "DRIVER={{ODBC Driver 17 for SQL Server}};SERVER={server_name}.database.windows.net;UID={username};PWD={password};DATABASE=mydatabase" cnxn = pyodbc.connect(conn_string) cursor = cnxn.cursor()
try: cursor.execute("INSERT INTO mytable (column1, column2) VALUES ('value1', 'value2')") cnxn.commit() logging.info("Successfully inserted record to SQL DWH pool") except Exception as e: logging.error("Error while inserting record to SQL DWH pool: {}".format(str(e))) cnxn.rollback()