Re: oci connect_string & c

From: Alligator Company <pnirff_at_T-Online.de>
Date: Wed, 9 Oct 2002 23:08:17 +0200
Message-ID: <ao25tb$1e6$06$1_at_news.t-online.com>


Hello Jesse,

here is a example from our kernel routine AlligatorSQL. I have extract the connect for you in OCI8.

Hope that help ? - otherwise contact me at m.peter_at_alligatorsql.de

Manfred
(Alligator Company GmbH)
http://www.alligatorsql.com

  • SNIP ------------------------- sword AOracleConnection::connectOCI8(OraText *username, OraText *password, OraText *database) { LOGOUTPUT("AOracleConnection::connect with OCI8 -> Try to connect to Oracle"); CString sDatabase;
    sDatabase.Format("%s", database);
    sDatabase.TrimRight();
    sDatabase.TrimLeft();

    m_bInitDebugger = FALSE;
    m_sInitDebugString.Format("", 0);
 this->m_sMainUser.Format("%s", username);
 this->m_sMainDatabase.Format("%s", database);
 this->m_sMainAlias.Format("", 0);

    sword status;
    if(state == connected) {
  // this object is already connected
  LOGOUTPUT("Connection already established");   return (CONERR_ALRCON);
 }

 /*******************************************************/
 /* set attribute server context in the service context */
 /*******************************************************/
 OCIAttrSet((dvoid *)m_svchp, OCI_HTYPE_SVCCTX, (dvoid *)m_srvhp,
(ub4)0, OCI_ATTR_SERVER, (OCIError *)m_errhp);

 OCIHandleAlloc((dvoid *)m_envhp, (dvoid **)&m_authp,
(ub4)OCI_HTYPE_SESSION, (size_t)0, (dvoid **)0);

    OCIAttrSet((dvoid *)m_authp, (ub4)OCI_HTYPE_SESSION, (dvoid *)username,
(ub4)strlen((char *)username), (ub4)OCI_ATTR_USERNAME, m_errhp);

 OCIAttrSet((dvoid *)m_authp, (ub4)OCI_HTYPE_SESSION, (dvoid *)password, (ub4) strlen((char *)password),
(ub4)OCI_ATTR_PASSWORD, m_errhp);

    if((status = OCILogon(m_envhp, m_errhp, &m_svchp, username, (ub4)strlen((char *)username),
  password, (ub4)strlen((char *)password), database, (ub4)strlen((char *)database))) == OCI_SUCCESS) {
  // successful login
  theUser.Format("%s", username);
  thePassword.Format("%s", password);
  if(database[0] == '\0')
   database = (OraText *)" ";
  theDatabase.Format("%s", database);

     state = connected;

  // save statistic
  theApp.IncreaseOracleConnect();
  LOGOUTPUT("AOracleConnection::connect OCI8 -> Connection successfully established");
 }
 else {
  display_error();
  CString s;
  s.Format("AOracleConnection::connect OCI8 -> Error while connecting to Oracle ErrorCode : %i", status);
  LOGOUTPUT(s.GetBuffer(0));
 }

  return(status);
}


Jesse Waters <jcwaters_at_wfubmc.edu> schrieb in im Newsbeitrag: ao1lur$1bu0$1_at_f1n1.spenet.wfu.edu...
> How do programmatically set the right connect_string using OCI? I see that
> to set the username and password that I use OCIAttrSet but I don't know the

> correct way to set the database to which I will connect.
>
> As an example when I login to sqlplus I must use:
> sqlplus> username/password_at_connect_string
> to get in.  The connect_string points me to the right database.  I know I
> must do this in my c code as well I just do not know how.  Any takers?
>
> Thankx,
> Jesse.
>
>
Received on Wed Oct 09 2002 - 23:08:17 CEST

Original text of this message