Connecting to Oracle using Pro*C/C++ [message #93867] |
Wed, 26 February 2003 09:35 |
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 #94113 is a reply to message #93875] |
Mon, 01 March 2004 03:15 |
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 #94142 is a reply to message #93867] |
Tue, 30 March 2004 04:01 |
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 #94236 is a reply to message #93867] |
Tue, 01 June 2004 08:27 |
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 #279321 is a reply to message #93867] |
Wed, 07 November 2007 15:24 |
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 |
|
Michel Cadot
Messages: 68731 Registered: March 2007 Location: Saint-Maur, France, https...
|
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
|
|
|