OCCI connect DB, but TNS error [message #131731] |
Tue, 09 August 2005 03:58 |
zhiyangemmett
Messages: 3 Registered: August 2005 Location: china
|
Junior Member |
|
|
I am new to OCCI and am using C++ to access Oracle database. compiling is correct, but can not connect to database.
it issued the error TNS -12154 : can not resolve the tnsname,
but when I using tnsping to test my tnsname, it goes well. and so does the SQL*plus.
I also test the same programm on another machine, it goes well as well.
but it just can not be right on my machine, any idea what is going on?
Any one got a solution??!
zhiyang
|
|
|
Re: OCCI connect DB, but TNS error [message #131739 is a reply to message #131731] |
Tue, 09 August 2005 04:33 |
zhiyangemmett
Messages: 3 Registered: August 2005 Location: china
|
Junior Member |
|
|
hi:
fellowing are some test info from my machine,
usr: cggroup
pwd: cggroup
db: cgdb
1. when I running my programm:
Exception thrown for Connection
Error number: 12154
ORA-12154: TNS:could not resolve the connect identifier specified
2.my tns config from my tnsnames.ora
CGDB =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.200.20)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = cgdb)
)
)
3. tnsping result:
C:\>tnsping cgdb
TNS Ping Utility for 32-bit Windows: Version 9.2.0.1.0 - Production on 09-08 -2005 17:39:07
Copyright (c) 1997 Oracle Corporation. All rights reserved.
using parameter file:
D:\oracle\ora92\network\admin\sqlnet.ora
using TNSNAMES adaptor to resolve service name
Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)
(HOST = 192.168.200.20)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = cgdb)))
OK(10ms)
someone help me! thanks
zhiyang
|
|
|
|
Re: OCCI connect DB, but TNS error [message #132567 is a reply to message #132340] |
Sun, 14 August 2005 19:57 |
zhiyangemmett
Messages: 3 Registered: August 2005 Location: china
|
Junior Member |
|
|
following is my connecting source code
#include <iostream>
#include <occi.h>
using namespace oracle::occi;
using namespace std;
#pragma comment(lib,"oraocci10.lib")
int main (void)
{
Environment *env = NULL;
Connection *con = NULL;
//Statement *stm;
env = Environment::createEnvironment();
OCCI_STD_NAMESPACE::string user = "cggroup";
OCCI_STD_NAMESPACE::string passwd = "cggroup";
OCCI_STD_NAMESPACE::string db = "cgdb";
try
{
con = env->createConnection(user,passwd,db);
}
catch(SQLException ex)
{
cout<<"Exception thrown for Connection"<<endl;
cout<<"Error number: "<< ex.getErrorCode() << endl;
cout<<ex.getMessage() << endl;
}
printf("Connect to DataBase Successfully!\n");
env->terminateConnection(con);
Environment::terminateEnvironment(env);
return 0;
}
|
|
|
|