tryconnection.py 1.1 KB

123456789101112131415161718192021222324252627282930
  1. remote = False # automatic testing of remote access has been removed here
  2. def try_connection(verbose, *args, **kwargs):
  3. import adodbapi
  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('***Failed getting connection using=',repr(args),repr(kwargs))
  14. return False, (args, kwargs), None
  15. print(" (successful)")
  16. return True, (args, kwargs, remote), dbconnect
  17. def try_operation_with_expected_exception(expected_exception_list, some_function, *args, **kwargs):
  18. try:
  19. some_function(*args, **kwargs)
  20. except expected_exception_list as e:
  21. return True, e
  22. except:
  23. raise # an exception other than the expected occurred
  24. return False, 'The expected exception did not occur'