Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Connect to Different Databases in Pro*C

Re: Connect to Different Databases in Pro*C

From: Bob Sauer <rsauer_at_census.gov>
Date: 1997/09/25
Message-ID: <342A82F0.126D@census.gov>#1/1

Nick,

You're on the right track. You can connect to multiple databases as follows:

EXEC SQL

   CONNECT        :username
   IDENTIFIED BY  :password
   AT             :db_alias
   USING          :db_name;

where db_alias is a tag applied to the connection and db_name is the SQL*Net syntax for logging into a remote database (look in TNSNAMES.ORA.) Then each time you issue an sql statement, you have to tell it on which database you want it to execute. For example:

EXEC SQL
   AT :db_alias
   UPDATE my_table
   SET foo = bar
   WHERE ... Hope this helps,
Bob

Standard disclaimers apply
nick_at_embassy.org wrote:
>
> Hi all,
>
> I tried to use the following Pro*C statement to connect to different
> oracle database instance on the same Solaris machine.
>
> EXEC SQL CONNECT :username IDENTIFIED BY :password AT :databasename;
>
> The statement executes and returns succesfully, but all the subsequent
> EXEC SQL EXECUTE calls return with an error of not logged on.
>
> If I remove "AT: databasename" in the above connect statement, i.e. to use
> the default database specified by ORACLE_SID environment variable, then
> all the subsequent EXEC SQL EXECUTE calls get executed successfully. But
> this limits the application's ability to connect to only one single
> database.
>
> So, what's the correct way to connect to different database server in
> Pro*C?
>
> I appreciate any helpful information.
>
> Nick Chang
>
> -------------------==== Posted via Deja News ====-----------------------
> http://www.dejanews.com/ Search, Read, Post to Usenet
Received on Thu Sep 25 1997 - 00:00:00 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US