Created with Raphaël 2.1.0
    Loading...
Skip to end of metadata
Go to start of metadata

ORACLE

EXEC SQL CONNECT { :user IDENTIFIED BY :oldpswd | :usr_psw }
  [{ AT [dbname | :host_variable }] USING :connect_string ]
    [ {ALTER AUTHORIZATION :newpswd | IN { SYSDBA | SYSOPER } MODE } ];

Sample Code

char *username = "SCOTT";
char *password = "TIGER";
...
EXEC SQL WHENEVER SQLERROR ...
EXEC SQL CONNECT :username IDENTIFIED BY :password;

ALTIBASE

EXEC SQL {AT :host_variable} CONNECT { :user IDENTIFIED BY :user_passwd} {USING :connect_string};

Sample Code

char *username = "SYS";
char *password = "MANAGER";
...
EXEC SQL WHENEVER SQLERROR ...
EXEC SQL CONNECT :username IDENTIFIED BY :password;
  • APRE doesn't support a syntax like "ALTER AUTHORIZATION".
  • APRE doesn't support a syntax like "IN {SYSDBA | SYSOPER} MODE".
  • APRE doesn't support a functionality for auto-connection.

Using AT

When you need to connect multiple database connections, use "AT" in your application source.

We recommend you to use independent connection name using AT clause for each connections.

char usr[20];
char pwd[20];
char conn_name1[20];
char conn_name2[20];
...
sprintf (usr, "SYS");
sprintf (pwd, "MANAGER");
sprintf (conn_name1, "db_connection1");
sprintf (conn_name2, "db_connection2");
 
EXEC SQL AT :conn_name1 CONNECT :usr IDENTIFIED BY :pwd;
EXEC SQL AT :conn_name2 CONNECT :usr IDENTIFIED BY :pwd;
...
EXEC SQL AT :conn_name1 SELECT ...;
EXEC SQL AT :conn_name2 PREPARE ...;
  • ALTIBASE HDB doesn't provide context for multi-thread application. Therefore, User has to manage connections for multi-thread application.

Using connect_string

When you need to specifiy a target database, use "USING" in your application source.

char usr[20];
char pwd[20];
char conn_string[200];
...
sprintf (usr, "SYS");
sprintf (pwd, "MANAGER");
sprintf (conn_string, "DSN=192.168.1.35;PORT_NO=20300;NLS_USE=US7ASCII;CONN_TYPE=1");
EXEC SQL CONNECT :usr IDENTIFIED BY :pwd USING :conn_string;

Option

Meaning

DSN

To specify IP of database server.

PORT_NO

To specify PORT_NO of database server.

NLS_USE

To specify national character set of database server.

CONN_TYPE

To specify connection-type.

  • CONN_TYPE=1 : TCP/IP type
  • CONN_TYPE=2 : UNIX Domain Socket type
  • CONN_TYPE=3 : IPC type (use shared-memory area for communication buffer.)

TIMEOUT=n

To specify time-limitation of interval for trying to connect to DB-server.

CONNECTION_TIMEOUT=n

To specify time-limitation of interval for receiving a packet about result of SQL executed.

  • If you don't specify a connection_string, application tries to connect to a local-server.
  • TIMEOUT and CONNECTION_TIMEOUT are used to check immediately a network-error in your application.
  • You can set a OS user-environment variable to connect to a database.
    export ALTIBASE_NLS_USE=US7ASCII
    export ALTIBASE_PORT_NO=20300

FailOver on application-side

AlTIBASE HDB provides functionality to fail-over, we called it as CTF and STF.
CTF is an acronym of Connection-Time-Failover and STF means Service-Time-Failover.
CTF is used when application tries to connect to a DBMS and gets an error for connection, application automatically tries to connect to an other DBMS which user defined.
STF is a available when application tries to execute a SQL and gets an connection-error (as DBMS or Server was down) for connection, application automatically tries to connect to an other DBMS which user defined.

Sample Code-1

EXEC SQL BEGIN DECLARE SECTION;
char usr[20];
char pwd[20];
char connt_opt[200];
EXEC SQL END DECLARE SECTION;
 
sprintf (usr, "SYS");
sprintf (pwd, "MANAGER");
sprintf (conn_opt, "DSN=192.168.3.54;PORT_NO=20300;CONNTYPE=1;AlternateServers=(192.168.3.54:20300,192.168.3.53:20300);ConnectionRetryCount=3;
 ConnectionRetryDelay=5;LoadBalance=on;SessionFailOver=on;"" );
 
EXEC SQL CONNECT :usr IDENTIFIED BY :pwd USING :conn_opt;
...

If fail to connect to "192.168.3.54", application automatically tries to connect to "192.168.3.53" after 5 seconds.

Sample Code-2

EXEC SQL BEGIN DECLARE SECTION;
char usr[20];
char pwd[20];
char connt_opt[200];
EXEC SQL END DECLARE SECTION;
 
sprintf (usr, "SYS");
sprintf (pwd, "MANAGER");
sprintf (conn_opt, "DSN=192.168.3.54;PORT_NO=20300;CONNTYPE=1;AlternateServers=(192.168.3.54:20300,192.168.3.53:20300);ConnectionRetryCount=3;
 ConnectionRetryDelay=5;LoadBalance=on;SessionFailOver=on;"" );
 
EXEC SQL CONNECT :usr IDENTIFIED BY :pwd USING :conn_opt;
...
...
EXEC SQL INSERT INTO table VALUES (:....);
if (sqlca.sqlcode != 0)
{
  if (SQLCODE == EMBEDED_ALTIBASE_FAILOVER_SUCCESS)
  {
      goto retry_statement;
  }
}


In the code above, When execute a insert-SQL, STF happens.
If user uses STF-functionality, User has to check a error-code as "EMBEDED_ALTIBASE_FAILOVER_SUCCESS".
STF functionality doesn't replay a transaction before failover, only reconnect to other server without having session-related information.
Therefore, user needs to write an additional code to replay.

Properties

Description

AlternateServers

User describes target-servers when connection-error happened.

ConnectionRetryDelay

After this time(second) elapses, application tries to connect to other server.

SessionFailOver

User defines to use STF-functionality or not

  • No labels