defineDatabaseAlias()

The system function SysLib.defineDatabaseAlias creates an alias that can be used to establish a new connection to a database to which your code is already connected. Once established, the alias can be used in any of these functions:

The alias can also be used in the connectionName field of a variable of type ReportData.

  SysLib.defineDatabaseAlias(
    alias STRING in,
    database STRING in)
alias
A string literal or variable that acts as an alias of the connection identified in the second parameter. The alias is case-insensitive.
database
A database name that was specified in SysLib.connect or VGLib.connectionService. Use a literal or variable of a character type.

If you do not specify a connection, the function affects the current connection.

Examples are as follows:
  // Connect to a database with alias "alias", 
  // which becomes the current connection.
  defineDatabaseAlias( "alias", "database" );
  connect( "alias", "user", "pwd" );

  // Make two connections to the same database.
  String db = "database";
  defineDatabaseAlias( "alias1", db );
  defineDatabaseAlias( "alias2", db );
  connect( "alias1", "user", "pwd" );
  connect( "alias2", "user", "pwd" );

  // Another way to make two connections 
  // to the same database.
  defineDatabaseAlias( "alias", "database" );
  connect( "alias", "user", "pwd" );
  connect( "database", "user", "pwd" );

  // An alias is defined but not used. The second 
  // connect() does not create a new connection.
  defineDatabaseAlias( "alias", "database" );
  connect( "database", "user", "pwd" );
  connect( "database", "user", "pwd" );

  // Use of an alias (which is case-insensitive)
  // when disconnecting.   
  defineDatabaseAlias( "alias", "database" );
  connect( "aLiAs", "user", "pwd" );
  disconnect( "ALIAS" );

  // The next disconnect call fails because the 
  // connection is called "alias" not "database".
  defineDatabaseAlias( "alias", "database" );
  connect( "alias", "user", "pwd" );
  disconnect( "database" );

  // An alias may change. After the next call, 
  // "alias" refers to "firstDatabase" 
  defineDatabaseAlias( "alias", "firstDatabase" );

  // After  the next call, 
  // "alias" refers to "secondDatabase".  
  defineDatabaseAlias( "alias", "secondDatabase" );

  // The last call would have failed 
  // if a connection was in place with "alias".

Related concepts
Syntax diagram for EGL functions
SQL support

Related reference
beginDatabaseTransaction()connect()
disconnect()
setCurrentDatabase()
connectionService()

Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.