import pyodbc print() try: connection = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=.;DATABASE=SampleDB;Trusted_Connection=yes') cursor = connection.cursor() cursor.execute("select @@version as version") while 1: row = cursor.fetchone() if not row: break print(row.version) cursor.close() connection.close() except pyodbc.Error as ex: print() print("exception: ",ex) print("closing program") print() exit() print()