How do I connect to a database using Pro*C?

suvitha picture suvitha · Jan 28, 2011 · Viewed 13k times · Source

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.

Answer

paxdiablo picture paxdiablo · Jan 28, 2011

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.