Home » Developer & Programmer » Precompilers, OCI & OCCI » Why am I getting an OCI_INVALID_HANDLE from OCISessionBegin?
Why am I getting an OCI_INVALID_HANDLE from OCISessionBegin? [message #93602] Mon, 29 July 2002 15:56 Go to next message
Timothy Knox
Messages: 2
Registered: July 2002
Junior Member
In the code below, I get an OCI_INVALID_HANDLE at the OCISessionBegin call. I have consulted the OCI Programmer's Guide, but it gives me no guidance. I went searching for a good book on OCI programming, to no avail. "Help me, Obi-Wan, you're my only hope." :)

Anyway, if somebody can point me in the right direction as to where I have screwed up, I would surely appreciate it. Thanks in advance.

<--- begin --->
static int log_db_err (sword retval, OCIError *err); /* Log any Oracle errors to syslog */

static OCIEnv *dbenv;
static OCIServer *dbsrv;
static OCIError *dberr;
static OCISvcCtx *dbsvc;
static OCISession *dbsess;

int setup_database (struct db_info *info) {
sword retval;

retval = OCIEnvCreate (&dbenv, OCI_DEFAULT | OCI_THREADED | OCI_SHARED,
NULL, NULL, NULL, NULL, 0, NULL);
if (retval != OCI_SUCCESS)
return (log_db_err (retval, NULL));

retval = OCIHandleAlloc (dbenv, &dberr, OCI_HTYPE_ERROR, 0, NULL);
if (retval != OCI_SUCCESS)
return (log_db_err (retval, NULL));

retval = OCIHandleAlloc (dbenv, &dbsrv, OCI_HTYPE_SERVER, 0, NULL);
if (retval != OCI_SUCCESS)
return (log_db_err (retval, NULL));

retval = OCIServerAttach (dbsrv, dberr, info->database, strlen (info->database), OCI_DEFAULT);
if (retval != OCI_SUCCESS)
return (log_db_err (retval, dberr));

retval = OCIHandleAlloc (dbenv, &dbsvc, OCI_HTYPE_SVCCTX, 0, NULL);
if (retval != OCI_SUCCESS)
return (log_db_err (retval, NULL));

retval = OCIAttrSet (dbsvc, OCI_HTYPE_SVCCTX, dbsrv, 0, OCI_ATTR_SERVER, dberr);
if (retval != OCI_SUCCESS)
return (log_db_err (retval, dberr));

retval = OCIHandleAlloc (dbenv, &dbsess, OCI_HTYPE_SESSION, 0, NULL);
if (retval != OCI_SUCCESS)
return (log_db_err (retval, NULL));

retval = OCIAttrSet (dbsess, OCI_HTYPE_SESSION, info->user, strlen (info->user), OCI_ATTR_USERNAME, dberr);
if (retval != OCI_SUCCESS)
return (log_db_err (retval, dberr));

retval = OCIAttrSet (dbsess, OCI_HTYPE_SESSION, info->passwd, strlen (info->passwd), OCI_ATTR_PASSWORD, dberr);
if (retval != OCI_SUCCESS)
return (log_db_err (retval, dberr));

retval = OCISessionBegin (dbsvc, dberr, dbsess, OCI_CRED_RDBMS, OCI_DEFAULT);
if (retval != OCI_SUCCESS)
return (log_db_err (retval, dberr));

retval = OCIAttrSet (dbsvc, OCI_HTYPE_SVCCTX, dbsess, 0, OCI_ATTR_SESSION, dberr);
return (log_db_err (retval, dberr));
}
<---- end ---->

Timothy Knox
Re: Why am I getting an OCI_INVALID_HANDLE from OCISessionBegin? [message #93605 is a reply to message #93602] Tue, 30 July 2002 06:28 Go to previous message
Timothy Knox
Messages: 2
Registered: July 2002
Junior Member
Never mind. :) It turns out the gcc optimiser was doing wonky things behind my back. I have turned it off, but now I am getting a different problem. I'll be back if I can't figure it out myself.
Previous Topic: ORA-12560 TNS:protocol adapter error
Next Topic: Pthread internal error while execution
Goto Forum:
  


Current Time: Sun Nov 24 13:20:51 CST 2024