Pro*c Concurrent database connection, establish database chain __ Database

Source: Internet
Author: User
Tags create database sql create database

/*
* This feature is mainly demo, while connecting two concurrent databases
*/

/* contains C header file * *
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* Contains SQLCA header file * *
EXEC SQL INCLUDE Sqlca;
EXEC SQL INCLUDE Sqlda;

int main ()
{
EXEC SQL BEGIN DECLARE section;
int money;
Char answerbuff[200];
int flag;
EXEC SQL end DECLARE section;

/*
* Define input Host variables: Receive user name, password, and network service name
*
*/
Char username[10],password[10],server[10], conn_var[20];
strcpy (username, "data_center");
strcpy (password, "Data_center");
strcpy (server, "ORADF1"); * * Here is the database of the sid*/
strcpy (Conn_var, "Llcore");

   /* Connect to default database */
    EXEC SQL connect:username identified by:p Assword Using:serve R
    if (sqlca.sqlcode==0)
        printf ("Default connection succeeded!/n");
    Else
       /* Display connection Error messages */
         printf ("%.*s/n", SQLCA.SQLERRM.SQLERRML,
                 SQLCA.SQLERRM.SQLERRMC);
   /* Disconnect database connection */
    EXEC SQL COMMIT release;
    printf ("Disconnect!/n");;

/* Connect to non-default Database * *
/* Here are two ways to connect, only one and the default way to maintain the same speech * *
EXEC SQL Connect:username identified by:p Assword At:conn_var Using:server;
if (sqlca.sqlcode==0)
printf ("Non-default connection successful!/n");
Else
/* Display Connection error message * *
printf ("%.*s/n", SQLCA.SQLERRM.SQLERRML,
SQLCA.SQLERRM.SQLERRMC);
/* Disconnect database Connection/*
EXEC SQL COMMIT release;
printf ("Disconnect!/n");
}

Concurrent connections are the establishment and use of multiple external database connections in the same database application. When you use concurrent connections, you are independent of the different connections, and the SQL statements and transaction operations of the different connections are independent of each other, without any relationship.

The database chain includes a common database chain and a private database chain.

CREATE Public DATABASE LINK

CREATE DATABASE LINK

In the PC source program to establish a database chain, with the following statement:

EXEC SQL CREATE DATABASE LINK name CONNECT to user name identified by Password USING ' table name ';


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.