Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: OCI - Connecting to Database
Hi,
Here is my Connect function. It sets acServiceName passed as a
parameter ( the one matching tnsnames.ora)
//-------------------------------------------------------- // // NAME : TQueryClass::Connect // // DESCRIPTION : Establishes connection to the database //
//---------------------------------------------------------- int TQueryClass::Connect ( const char * acUserName, const char * acPassword, const char * acServiceName ){
char acSQLFootPrint [ 256];
sprintf ( acSQLFootPrint,
"/* Program started.\r\n\r\n User %s is connecting */\r\n\r\n ", acUserName ); m_prSQLQueryFile->Write ( acSQLFootPrint, strlen ( acSQLFootPrint ) - 4 );
/*
OCIEnvInit (&or8EnvHandle, OCI_DEFAULT, 0, (dvoid **) 0);
/*
if (oci8Error (OCIHandleAlloc ((dvoid *) or8EnvHandle, (dvoid * *) &or8SrcHandle, OCI_HTYPE_SVCCTX, 0, (dvoid * *) 0))) return OCI8_INITIALIZED; if (oci8Error (OCIHandleAlloc ((dvoid *) or8EnvHandle, (dvoid * *) &or8ErrorHandle, OCI_HTYPE_ERROR, 0, (dvoid * *) 0))) return OCI8_INITIALIZED;
/*
if (oci8Error (OCIAttrSet ((dvoid *) or8SrcHandle,
OCI_HTYPE_SVCCTX,
(dvoid *) or8SrvrHandle, (ub4) 0,
OCI_ATTR_SERVER,
or8ErrorHandle))) return OCI8_SERVER_ATTACHED;
/*
if (oci8Error (OCIAttrSet ((dvoid *) or8UsrHandle,
OCI_HTYPE_SESSION,
(dvoid *) acUserName, (ub4) strlen
(acUserName),
OCI_ATTR_USERNAME, or8ErrorHandle))) return OCI8_SERVER_ATTACHED; if (oci8Error (OCIAttrSet ((dvoid *) or8UsrHandle, OCI_HTYPE_SESSION, (dvoid *) acPassword, (ub4) strlen (acPassword), OCI_ATTR_PASSWORD, or8ErrorHandle))) return OCI8_SERVER_ATTACHED; if (oci8Error (OCISessionBegin (or8SrcHandle, or8ErrorHandle, or8UsrHandle, OCI_CRED_RDBMS, OCI_DEFAULT))) return OCI8_SERVER_ATTACHED; if (oci8Error (OCIAttrSet ((dvoid *) or8SrcHandle, OCI_HTYPE_SVCCTX, (dvoid *) or8UsrHandle, (ub4) 0, OCI_ATTR_SESSION, or8ErrorHandle))) return OCI8_SESSION_BEGAN;
/*
In article <17599f0b.0f3d7f99_at_usw-ex0107-042.remarq.com>, Harish <hdeshpandeNOhdSPAM_at_carlson.com.invalid> wrote:
> Hi, > > I have developed a client/server application using OCI on NT 4.0. > When I converted this application to an NT service I found that it is > connecting to a different database. I do not know how it isconnecting
> to a different database as the connect string is the same. One way to > overcome this problem is to supply the connect description in the > connect call it is possible. Can one any of you please provide mewith
> a sample for this. Oracle documentation does not have a sample for > this. > > My current connect string is as follows: uname/passwd_at_dbname > > I want to know if this can be changed to: uname/passwd@(x) where x > is similar to an entry in 'tnsname.ora'. > > Thanks in advance for your time and help. > > Harish > > * Sent from RemarQ http://www.remarq.com The Internet's DiscussionNetwork *
Sent via Deja.com http://www.deja.com/
Before you buy.
Received on Thu Jan 06 2000 - 17:25:19 CST