Hina Softwares, Kattumannarkoil

Oracle Forms -Change Connection Procedure



FUNCTION CHANGE_CONNECTION (
  v_conHandle IN OUT EXEC_SQL.ConnType,
  v_conInfo IN OUT VARCHAR2,
  v_userName IN VARCHAR2 DEFAULT NULL,
  v_password IN VARCHAR2 DEFAULT NULL,
  v_datasource IN VARCHAR2 DEFAULT NULL
) RETURN BOOLEAN IS

  -- This procedure tries to open a connection to
  -- v_username/v_password@v_datasource.  If it succeeds,
  -- it disconnects from the connection on v_conHandle (if there
  -- is one), and sets v_conHandle to point to the new
  -- connection.  If the user hits Cancel on the LOGON_SCREEN
  -- dialog, this function silently returns with the same connection.
  -- If it fails to log on, it will display an alert and bring you
  -- back to the LOGON screen.  You get a maximum of

  c_attempts CONSTANT INTEGER := 3;

  -- attempts to log on.  If after all attempts, you still fail, the
  -- function returns with the same connection handle as it was
  -- passed.
  -- If the connection is changed, v_conInfo will contain
  -- the string v_userName@v_datasource, or if datasource is NULL,
  -- v_userName@(Oracle)

  un VARCHAR2(80);
  pw VARCHAR2(80);
  cn VARCHAR2(80);
  tmpConInfo VARCHAR2(255);
  tmpConHandle EXEC_SQL.ConnType;
  logonSuccessful BOOLEAN := FALSE;

BEGIN
  FOR i IN 1..c_attempts LOOP
    IF v_username is not null or
       v_password is not null or
       v_datasource is not null THEN
      IF i > 1 THEN
        -- Only one attempt if the username/password is specified
        EXIT;
      END IF;
      un := v_username ;
      pw := v_password;
      cn := v_datasource;
    ELSE
     -- LOGON_SCREEN;
      Get_Connect_Info ( un, pw, cn );
    
    END IF;
    IF ((un is null) and (pw is null) and (cn is null)) THEN
      -- We assume this is cancel, as we have no other way
      -- of telling.
      EXIT;
    END IF;
    BEGIN
 --     tmpConHandle := EXEC_SQL.OPEN_CONNECTION(un, pw, cn);
    tmpConHandle := EXEC_SQL.OPEN_CONNECTION('nip', 'nip', 'nip');
    EXCEPTION
    WHEN EXEC_SQL.PACKAGE_ERROR THEN
      -- We failed to log on.
      DECLARE
        tmpAlert PLS_INTEGER;
      BEGIN
        tmpAlert := SHOW_ALERT('LOGON_FAILED');
      END;
    END;
    IF EXEC_SQL.VALID_CONNECTION(tmpConHandle) THEN
      -- We succeeded in connection.  Disconnect old handle,
      -- and set all output variables.
      IF cn IS NULL THEN
        cn := '(Oracle)';
      END IF;
      EXEC_SQL.CLOSE_CONNECTION(v_conHandle);
      v_conHandle := tmpConHandle;
      v_conInfo := un || '@' || cn;
      logonSuccessful := TRUE;
      -- And break the loop.
      EXIT;
    END IF;
  END LOOP;
  IF logonSuccessful THEN
    RETURN TRUE;
  ELSE
    RETURN FALSE;
  END IF;
END;


Responses

0 Respones to "Oracle Forms -Change Connection Procedure"

Post a Comment

Comment

 

Recent Comments

Popular Posts

Return to top of page Copyright © 2010 | Hina Softwares