Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SAP Sybase SQL Anywhere 16.0 » SQL Anywhere Server - Database Administration » High availability and read-only scale-out systems » Database mirroring » Application development considerations with database mirroring

 

Connecting to a database in a mirroring system

Connect to the database on either the primary or mirror server by specifying the alternate name for the respective server with the ServerName connection parameter, along with the addresses for both partner servers with the Host connection parameter.

Prérequis

The mirroring server partners must be running.

Contexte et remarques

In a mirroring system, you do not necessarily know which database server is acting as the primary server and which one is acting as the mirror server.

Create clients that can reconnect to the database (for example, when failover occurs the user may need to shut down the application and then restart it).

 Task
  • To connect to the primary or mirror server running the mirrored database, the connection string must include the following connection parameters:

    • Server  

      • To connect to the primary server   Choose one of the following options:

        Option Action
        ServerName connection parameter

        Specify the alternate server name for the primary database server in the database mirroring system. This is the name that is defined by the CREATE MIRROR SERVER primary_alternate_server_name AS PRIMARY ... statement.

        NodeType connection parameter

        Set the NodeType (Node) connection parameter to MIRROR in the connection string.

      • To connect to the mirror server   Choose one of the following options

        Option Action
        ServerName connection parameter

        Specify the alternate server name for the mirror database server in the database mirroring system. This is the name that is defined by the CREATE MIRROR SERVER mirror_alternate_server_name AS MIRROR ... statement.

        NodeType connection parameter

        Set the NodeType (Node) connection parameter to PRIMARY in the connection string.

    • HOST   Specify the addresses and ports for both partners to ensure that the connection succeeds regardless of which partner is currently the primary. The host and port information for each of the partners is defined in the connection string of the CREATE MIRROR SERVER partner_server_name AS PARTNER connection_string='SERVER=partner_server_name;host=host_name:port_number statements.

    You might want to specify the RetryConnectionTimeout connection parameter to control how long clients keep retrying the connection attempt to either database server.

Résultat

The client connects to the specified server

Exemple

For example, if the primary database server is named myprimary, clients specify the connection parameter Server=myprimary in their connection string:

...UID=user12;PWD=x92H4pY;Server=myprimary;HOST=myhost1:6871,myhost2:6872...

 See also

Queries executed on the mirror database
Event execution in a database mirroring or read-only scale-out system