with pyodbc.connect(conx_string) as conx: cursor = conx.cursor() cursor.execute(query) data = cursor.fetchall()