Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> OCIServerAttach returns ORA-12514

OCIServerAttach returns ORA-12514

From: Paul <paul.flew_at_globaladdress.net>
Date: 13 Aug 2006 10:49:54 -0700
Message-ID: <1155491394.373445.98770@m73g2000cwd.googlegroups.com>


Hi

I have a small C application which connects to an Oracle database using OCI. Please find a code snippet below. I currently have a problem that the code works when connecting to certain database instances but not to others (its all the same server version of Oracle). I have verified that the connection details are correct, and other applications are able to connect to the instance that my C program cannot.

The error I get returned from OCIServerAttach is ORA-12512: TNS:listener does not currently know of the service requested in connect descriptor.

I'm new to OCI and Oracle so any suggestions on where to start looking, or alternatively some suggestions on what may be wrong in the code would be appreciated.

Many thanks

Paul

Code snippet:

int GRIDChange(const char *sDBusername, const char *sDBpassword, const char *sDBserver, char *sStatus, char *sMessage) {
OCIEnv *envhp = (OCIEnv *) 0;
OCIError *errhp = (OCIError *) 0;
OCISession *authp = (OCISession *) 0;

OCIServer *srvhp = (OCIServer *) 0;
OCISvcCtx *svchp = (OCISvcCtx *) 0;
OCIStmt   *gridcall = (OCIStmt *) 0;

sword statusCheck;

/*
* Connect to ORACLE
*/

(void) OCIEnvNlsCreate( (OCIEnv **) &envhp, OCI_DEFAULT, (dvoid *)0,

(dvoid * (*)(dvoid *, size_t)) 0,
(dvoid * (* (dvoid *, dvoid *, size_t)) 0,
(void (*)(dvoid *, dvoid *)) 0, (size_t) 0,
(dvoid **) 0, (ub2) 871, (ub2) 871 ); // 871 = UTF8 encoding

(void) OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &errhp, OCI_HTYPE_ERROR,
(size_t) 0, (dvoid **) 0);

/* server contexts */
(void) OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &srvhp, OCI_HTYPE_SERVER,
(size_t) 0, (dvoid **) 0);

(void) OCIHandleAlloc( (dvoid *) envhp, (dvoid **) &svchp, OCI_HTYPE_SVCCTX,
(size_t) 0, (dvoid **) 0);

statusCheck = OCIServerAttach( srvhp, errhp, (text *) sDBserver, (ub4) strlen(sDBserver), 0);
if ( statusCheck )
{

	checkerr(errhp, statusCheck, sMessage);
	strcpy(sStatus, "FAILURE");
	cleanup(envhp, errhp, srvhp, svchp, authp, gridcall);
	return OCI_ERROR;

}

/* set attribute server context in the service context */ (void) OCIAttrSet( (dvoid *) svchp, OCI_HTYPE_SVCCTX, (dvoid *)srvhp,

(ub4) 0, OCI_ATTR_SERVER, (OCIError *) errhp);

(void) OCIHandleAlloc((dvoid *) envhp, (dvoid **)&authp,

(ub4) OCI_HTYPE_SESSION, (size_t) 0, (dvoid **) 0);

(void) OCIAttrSet((dvoid *) authp, (ub4) OCI_HTYPE_SESSION,

(dvoid *) sDBusername, (ub4) strlen(sDBusername),
(ub4) OCI_ATTR_USERNAME, errhp);

(void) OCIAttrSet((dvoid *) authp, (ub4) OCI_HTYPE_SESSION,

(dvoid *) sDBpassword, (ub4) strlen(sDBpassword),
(ub4) OCI_ATTR_PASSWORD, errhp);

statusCheck = OCISessionBegin ( svchp, errhp, authp, OCI_CRED_RDBMS, (ub4) OCI_DEFAULT );
if ( statusCheck )
{

	checkerr(errhp, statusCheck, sMessage);
	strcpy(sStatus, "FAILURE");
	cleanup(envhp, errhp, srvhp, svchp, authp, gridcall);
	return OCI_ERROR;

} Received on Sun Aug 13 2006 - 12:49:54 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US