Home » Developer & Programmer » Precompilers, OCI & OCCI » OCCI connect DB, but TNS error
OCCI connect DB, but TNS error [message #131731] Tue, 09 August 2005 03:58 Go to next message
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 Go to previous messageGo to next message
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 #132340 is a reply to message #131731] Fri, 12 August 2005 00:56 Go to previous messageGo to next message
kmohan
Messages: 28
Registered: July 2005
Junior Member
what is the connect string parameter value that you are passing to createConnection call?
Re: OCCI connect DB, but TNS error [message #132567 is a reply to message #132340] Sun, 14 August 2005 19:57 Go to previous messageGo to next message
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;


}
Re: OCCI connect DB, but TNS error [message #199962 is a reply to message #132567] Fri, 27 October 2006 03:39 Go to previous message
acorba67
Messages: 1
Registered: October 2006
Junior Member
Hi all
I have the same exctly problem?

All conncection sqlplus, tnsping, and so work fine.

But in C++ code (a very trivial code) NOT WORK!!!

Any help or suggestion?
Previous Topic: Connect in Unicode mode
Next Topic: Compilation of Pro*c Program
Goto Forum:
  


Current Time: Thu Mar 28 20:19:52 CDT 2024