Home » Developer & Programmer » Precompilers, OCI & OCCI » Connecting to Oracle using Pro*C/C++
Connecting to Oracle using Pro*C/C++ [message #93867] Wed, 26 February 2003 09:35 Go to next message
Siobhan
Messages: 1
Registered: February 2003
Junior Member
Hi,
Am just totally stuck on this problem and would be grateful for any suggestions.I have compiled a pro*C program to produce the C source file but don't seem to be able to connect to oracle. I am trying to run the rpoject within Microsoft Visual C++.This is a sample of the code .

//Program by Siobhan Mc Adam.
#include
#include
#include
#include

EXEC SQL BEGIN DECLARE SECTION;
char *userid="SYSTEM";
char *password="MANAGER";
char db_string[[20]]= "tester";
char db_name[[10]] = "TESTER";

EXEC SQL END DECLARE SECTION;

EXEC SQL DECLARE TESTER database;

int main()
{

char c[[100]];
EXEC SQL CONNECT :userid IDENTIFIED BY :password at :db_name using :db_string;
if (sqlca.sqlcode < 0) { /* There's an error in connecting. */
fprintf (stderr, "example: cannot connect to Oracle database.n");
exit (-1);

}
Re: Connecting to Oracle using Pro*C/C++ [message #93875 is a reply to message #93867] Sun, 02 March 2003 09:47 Go to previous messageGo to next message
langda
Messages: 5
Registered: March 2003
Junior Member
Check the sqlca.sqlcode and look for the Oracle Error Message which fits sqlca.sqlcode . This might help you.
Re: Connecting to Oracle using Pro*C/C+ [message #94113 is a reply to message #93875] Mon, 01 March 2004 03:15 Go to previous messageGo to next message
Mitesh K. Patel
Messages: 4
Registered: March 2004
Junior Member
hey i m also facing the same problem well if u get a way to connect it then let me also know it please, well just i know that is we need a pro*c compiler to do so might this help u, but see then again where to get pro*c compiler from and how to use it is a problem, well if u get to know about it the let me know about it on : mitesh_26@hotmail.com
Re: Connecting to Oracle using Pro*C/C+ [message #94125 is a reply to message #93867] Thu, 18 March 2004 05:51 Go to previous messageGo to next message
Janaka
Messages: 2
Registered: March 2004
Junior Member
could u plz send the explenation of database connectivity in c, c++
Re: Connecting to Oracle using Pro*C/C+ [message #94142 is a reply to message #93867] Tue, 30 March 2004 04:01 Go to previous messageGo to next message
Kaustubh Deshpande
Messages: 32
Registered: March 2004
Member
Hi,

I tried with your code (copy / paste) with my Oracle 9i
by changing db_string and database name and it worked fine. Connection was successful. I could issue select statement and could read the data.

Have you checked with sqlcode? what is the value of sqlcode.

Have you specified correct arguments in db_string and db_name.

regards,
Kaustubh
Re: Connecting to Oracle using Pro*C/C+ [message #94161 is a reply to message #93875] Sat, 10 April 2004 00:43 Go to previous messageGo to next message
alok
Messages: 12
Registered: December 2000
Junior Member
plz tell how to connect the c++ with the oracle.
thanx
alok
Re: Connecting to Oracle using Pro*C/C+ [message #94192 is a reply to message #94125] Mon, 03 May 2004 01:55 Go to previous messageGo to next message
anil vatshayanan
Messages: 1
Registered: May 2004
Junior Member
respected sir/madam
plz tell me way of connecting c++ with database like oracle and msaccess.
thanking you.
anilvats
anilvats76@rediffmail.com
Re: Connecting to Oracle using Pro*C/C+ [message #94236 is a reply to message #93867] Tue, 01 June 2004 08:27 Go to previous messageGo to next message
SANDY
Messages: 60
Registered: April 1998
Member
TRY THIS : IT REALLY WORKED:

char username[[15]] = "username";
char password[[15]] = "pswd";
char db_string1[[20]] = "dbstring"; /* eg, username/pswd@dbstring

void sql_error(char * msg)
{
printf(msg);
printf("Oracle Error %ld : %.*s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrml);
exit(-1);
}

EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error 1 --n");
EXEC SQL DECLARE DB_NAME1 DATABASE;
EXEC SQL CONNECT :username IDENTIFIED BY :password
AT DB_NAME1 USING :db_string1;
Re: Connecting to Oracle using Pro*C/C+ [message #94389 is a reply to message #93867] Tue, 28 September 2004 05:44 Go to previous messageGo to next message
Badri Patel
Messages: 1
Registered: September 2004
Junior Member
I am also facing same porblem, if you getsolution then please replay to me also.can you tell me from where to get prc*C/C++
thanks.
Re: Connecting to Oracle using Pro*C/C+ [message #94554 is a reply to message #93867] Tue, 01 February 2005 23:59 Go to previous messageGo to next message
Lalit Kumar
Messages: 2
Registered: September 2004
Junior Member
Pro *c/c++ compiler comes with Oracle.
Re: Connecting to Oracle using Pro*C/C++ [message #279321 is a reply to message #93867] Wed, 07 November 2007 15:24 Go to previous messageGo to next message
boludes
Messages: 7
Registered: October 2007
Location: Argentina
Junior Member

Hello, I'm from Argentina, and i have the next problem when i run the proyect, and I ask you for, What can I do with this problem, where I found the error, and resolve. Thank You SO MUCH!

ORACLE error--

ORA-12154: TNS:could not resolve service name

Press any key to continue
Re: Connecting to Oracle using Pro*C/C++ [message #279391 is a reply to message #279321] Thu, 08 November 2007 01:26 Go to previous message
Michel Cadot
Messages: 64152
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
ORA-12154: TNS:could not resolve the connect identifier specified
 *Cause:  A connection to a database or other service was requested using
 a connect identifier, and the connect identifier specified could not
 be resolved into a connect descriptor using one of the naming methods
 configured. For example, if the type of connect identifier used was a
 net service name then the net service name could not be found in a
 naming method repository, or the repository could not be
 located or reached.
 *Action:
   - If you are using local naming (TNSNAMES.ORA file):
      - Make sure that "TNSNAMES" is listed as one of the values of the
        NAMES.DIRECTORY_PATH parameter in the Oracle Net profile
        (SQLNET.ORA)
      - Verify that a TNSNAMES.ORA file exists and is in the proper
        directory and is accessible.
      - Check that the net service name used as the connect identifier
        exists in the TNSNAMES.ORA file.
      - Make sure there are no syntax errors anywhere in the TNSNAMES.ORA
        file.  Look for unmatched parentheses or stray characters. Errors
        in a TNSNAMES.ORA file may make it unusable.
   - If you are using directory naming:
      - Verify that "LDAP" is listed as one of the values of the
        NAMES.DIRETORY_PATH parameter in the Oracle Net profile
        (SQLNET.ORA).
      - Verify that the LDAP directory server is up and that it is
        accessible.
      - Verify that the net service name or database name used as the
        connect identifier is configured in the directory.
      - Verify that the default context being used is correct by
        specifying a fully qualified net service name or a full LDAP DN
        as the connect identifier
   - If you are using easy connect naming:
      - Verify that "EZCONNECT" is listed as one of the values of the
        NAMES.DIRETORY_PATH parameter in the Oracle Net profile
        (SQLNET.ORA).
      - Make sure the host, port and service name specified
        are correct.
      - Try enclosing the connect identifier in quote marks.

   See the Oracle Net Services Administrators Guide or the Oracle
   operating system specific guide for more information on naming.

Regards
Michel
Previous Topic: Problems using OCCI in a old linux version - RedHat 7.2
Next Topic: Pro*C/C++: EXEC SQL CONNECT TO "database" problem
Goto Forum:
  


Current Time: Sat Dec 10 15:02:00 CST 2016

Total time taken to generate the page: 0.09656 seconds