1 def try_connection(verbose, *args, **kwargs): 2 import adodbapi 3 4 dbconnect = adodbapi.connect 5 try: 6 s = dbconnect(*args, **kwargs) # connect to server 7 if verbose: 8 print("Connected to:", s.connection_string) 9 print("which has tables:", s.get_table_names()) 10 s.close() # thanks, it worked, goodbye 11 except adodbapi.DatabaseError as inst: 12 print(inst.args[0]) # should be the error message 13 print(f"***Failed getting connection using= {args!r} {kwargs!r}") 14 return False, (args, kwargs), None 15 16 print(" (successful)") 17 18 return True, (args, kwargs), dbconnect 19 20 21 def try_operation_with_expected_exception( 22 expected_exception_list, some_function, *args, **kwargs 23 ): 24 try: 25 some_function(*args, **kwargs) 26 except expected_exception_list as e: 27 return True, e 28 except: 29 raise # an exception other than the expected occurred 30 return False, "The expected exception did not occur" 31