def test_connection(self, source, caption): # check host 1st set_status_text = mforms.App.get().set_status_text set_status_text("Testing network connectivity to %s Server..." % caption) if test_connectivity(source.connection, "Test %s DBMS Connection" % caption) == False: set_status_text("%s server could not be contacted" % caption) return set_status_text("Testing connection to %s DBMS..." % caption) force_password = False attempt = 0 extra = "" is_odbc = is_odbc_connection(source.connection) while True: try: if not source.connect(): raise Exception("Could not connect to DBMS") source.disconnect() set_status_text("%s DBMS connection is OK" % caption) mforms.Utilities.show_message("Test %s DBMS Connection" % caption, "Connection succeeded.", "OK", "", "") if source.password is None: source.password = "" # connection succeeded with no password, so it must be blank break except (DBLoginError, SystemError), e: if attempt == 0 and "[Driver Manager]" in e.message and "image not found" in e.message: set_status_text("Specified ODBC driver not found") show_missing_driver_error(e) return elif attempt > 0: if isinstance(e, DBLoginError) and not force_password: force_password = True else: set_status_text("Could not connect to DBMS") if is_odbc: extra = "\n\nODBC connection string: %s" % get_odbc_connection_string(source.connection, '<your password>') etext = str(e) if etext.startswith("Error(") and ": error calling " in etext: try: etext = eval(etext[7:etext.rfind("):")-1], {}, {})[1] except: pass mforms.Utilities.show_message("Test %s DBMS Connection" % caption, "Could not connect to %s DBMS.\n%s%s" % (caption, etext, extra), "OK", "", "") return attempt += 1 username = source.connection.parameterValues.userName storage_string = source.connection.hostIdentifier source.password = request_password(source.connection, username, storage_string, force_password) # Avoid asking the password a second time when the user cancels the password request if source.password == None: mforms.Utilities.show_error("Test %s DBMS Connection" % caption, "Operation cancelled", "OK", "", "") break except migration.NotSupportedError, e: mforms.Utilities.show_message('Unsupported Connection Method', e.message, 'OK', '', '') return
def test_connection(self, source, caption): # check host 1st set_status_text = mforms.App.get().set_status_text set_status_text("Testing network connectivity to %s Server..." % caption) if test_connectivity(source.connection, "Test %s DBMS Connection" % caption) == False: set_status_text("%s server could not be contacted" % caption) return set_status_text("Testing connection to %s DBMS..." % caption) force_password = False attempt = 0 extra = "" is_odbc = is_odbc_connection(source.connection) while True: try: if not source.connect(): raise Exception("Could not connect to DBMS") source.disconnect() set_status_text("%s DBMS connection is OK" % caption) mforms.Utilities.show_message("Test %s DBMS Connection" % caption, "Connection succeeded.", "OK", "", "") if source.password is None: source.password = "" # connection succeeded with no password, so it must be blank break except (DBLoginError, SystemError), e: if attempt == 0 and "[Driver Manager]" in e.message and "image not found" in e.message: set_status_text("Specified ODBC driver not found") show_missing_driver_error(e) return elif attempt > 0: if isinstance(e, DBLoginError) and not force_password: force_password = True else: set_status_text("Could not connect to DBMS") if is_odbc: extra = "\n\nODBC connection string: %s" % get_odbc_connection_string(source.connection, '<your password>') etext = str(e) if etext.startswith("Error(") and ": error calling " in etext: try: etext = eval(etext[7:etext.rfind("):")-1], {}, {})[1] except: pass mforms.Utilities.show_message("Test %s DBMS Connection" % caption, "Could not connect to %s DBMS.\n%s%s" % (caption, etext, extra), "OK", "", "") return attempt += 1 source.password = request_password(source.connection, force_password) # Avoid asking the password a second time when the user cancels the password request if source.password == None: mforms.Utilities.show_error("Test %s DBMS Connection" % caption, "Operation cancelled", "OK", "", "") break except migration.NotSupportedError, e: mforms.Utilities.show_message('Unsupported Connection Method', e.message, 'OK', '', '') return
def test_connection(self, source, caption): # check host 1st set_status_text = mforms.App.get().set_status_text set_status_text("Testing network connectivity to %s Server..." % caption) if test_connectivity(self.panel.connection, "Test %s DBMS Connection" % caption) == False: set_status_text("%s server could not be contacted" % caption) return set_status_text("Testing connection to %s DBMS..." % caption) force_password = False attempt = 0 extra = "" is_odbc = is_odbc_connection(source.connection) while True: try: if not source.connect(): raise Exception("Could not connect to DBMS") set_status_text("%s DBMS connection is OK" % caption) mforms.Utilities.show_message( "Test %s DBMS Connection" % caption, "Connection succeded.", "OK", "", "") break except (DBLoginError, SystemError), e: if attempt == 0: if "[Driver Manager]" in e.message and "image not found" in e.message: set_status_text("Specified ODBC driver not found") show_missing_driver_error(e) return elif attempt > 0: if isinstance(e, DBLoginError) and not force_password: force_password = True else: set_status_text("Could not connect to DBMS") if is_odbc: extra = "\n\nODBC connection string: %s" % get_odbc_connection_string( source.connection, source.password) etext = str(e) if etext.startswith( "Error(") and ": error calling " in etext: try: etext = eval(etext[7:etext.rfind("):") - 1], {}, {})[1] except: pass mforms.Utilities.show_message( "Test %s DBMS Connection" % caption, "Could not connect to %s DBMS.\n%s%s" % (caption, etext, extra), "OK", "", "") return attempt += 1 source.password = request_password(source.connection, force_password) except Exception, e: set_status_text("Could not connect to DBMS: %s" % e) if is_odbc: extra = "\n\nODBC connection string: %s" % get_odbc_connection_string( source.connection, source.password) etext = str(e) if etext.startswith("Error(") and etext.endswith(")"): etext = eval(etext[6:-1], {}, {})[1] mforms.Utilities.show_message( "Test %s DBMS Connection" % caption, "Could not connect to the DBMS.\n%s%s" % (etext, extra), "OK", "", "")