As the title says, how do I connect to a given database in Oracle's Pro C? I don't want the connection for Oracle database but for some other database.
-
Hello, welcome to SO. I've edited your question to make sure it gets some answers as there's two close votes on it. If you aren't happy with the edits, feel free to roll it back and make your own. – Jan 28 '11 at 06:48
-
What sort of non-Oracle database ? Is it running on the same machine or over a network ? – Gary Myers Jan 28 '11 at 09:43
3 Answers
You use the exec sql connect
statement in your C code:
EXEC SQL CONNECT :myUserId IDENTIFIED BY :myPassword;
If you want to connect to a non-Oracle database, you will probably have to use the at
version of the command:
EXEC SQL CONNECT :myUserId IDENTIFIED BY :myPassword AT :myDbName;
and set up a database link in Oracle so that it can pass requests through to the other DBMS.
DBMS' like DB2 provide transparent gateways which can give you this facility without having to go through ODBC. It depends on which DBMS you're targeting as to how you'd go about setting this up.

- 854,327
- 234
- 1,573
- 1,953
From the documentation available here and in more detail here it looks like you can embed a CONNECT
statement directly in your code.
To quote the first article, a simplified connect statement would be:
EXEC SQL CONNECT { :user IDENTIFIED BY :oldpswd | :usr_psw }
[[ AT { dbname | :host_variable }] USING :connect_string ]
[ {ALTER AUTHORIZATION :newpswd | IN { SYSDBA | SYSOPER } MODE} ] ;
-
-
Certainly. See paxdiablo's answer for a simple method of connecting using host variables. The syntax above gives you more information, so for example you can connect to a non default database by specifying `AT dbname` where dbname is the identifier given to the database by Oracle. You can connect in operational (SYSOPER) mode by adding `IN SYSOPER` on to the end and as the dba using `IN SYSDBA`. For example. For more info, do check the first document link. – Jan 28 '11 at 07:09
-
Thank you. If the {AT dbname} is not supplied, as it is in my program, where is this specified as I currently cannot see which db my program is connecting to? – Beezer Nov 26 '20 at 07:49
Relevant answer here if you want to connect with oracle-pro-c, using an oracle-wallet.
Connecting to a database in Pro C using Oracle Wallet
Works great to have a wallet, and provide empty strings for :userId
and :userPassword
.
EXEC SQL CONNECT :mptyStr IDENTIFIED BY :mptyStr AT :ORACLE_SID;

- 8,193
- 15
- 41
- 69