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 -> Re: OCI question -- if you have souls please help!

Re: OCI question -- if you have souls please help!

From: Chris O <itoys1>
Date: Fri, 16 May 2003 17:53:12 +1000
Message-ID: <3ec498b3$0$25726$afc38c87@news.optusnet.com.au>


Hi Dave, Normall, All.

Norman is correct. You are using a very old version of the OCI libs. Oracle7 OCIs in fact.

I guess you will not want to port your code to Oracle8/9 OCIs so here goes.

The Oracle7 OCI is expecting two arrays of chars as the userid and password.fields [plus the other stuff].

You don't show what you are passing in the userid and password fields so I'll guess the username and password are both valid!

Since you said you can connect thru SQL*Plus on the same amchine, I'll assume you are using the same user account (and hence environment setting) as when you run the OCI test.

  1. You need to pass only the password in the password field.
  2. The userid field should contain (a) a username only -or- (b) username_at_db-string.

If you omit the @db-string then OCI will use the value of your unix TWO_TASK environment variable if it is set.
If neither are present the default database is assumed.

Now for the value of the db-string.

This is usually a TNS alias although you can use the TNS address specification (i.e. the LISP like structure you see in the tnsnames.ora). The names you listed with embedded semi-colons look like SQL*Net Version 1 syntax. This is no longer valid. Where did you get your examples? The last name that you listed does look OK.

What you have to do is to use either

 (a) the TWO_TASK environment variable with just <username> in the uid field -or-
 (b) Unset the TWO_TASK environment variable and use the <username>@<db-string> in the uid field. If you use both [from memory] the two-task var will be ignored.

Alternatively, do as Norman suggests and use the Oracle 8/9 OCIs. You will find all sorts of limitations with the Oracle 7 OCIs.

For one, you cannot select from LOBs [If you find out how I'd love to know].

When you see tools that support database identifiers such as <internet-domain-name>:<listener-port-number>:<sid> they translate this form into the TNS address specification BEFORE making the call to the OCIs.

Hope this helps

Chris

-- 

"D. Alvarado" <laredotornado_at_zipmail.com> wrote in message
news:9fe1f2ad.0305120956.170bb452_at_posting.google.com...

> Hi,
> I am trying to write an Apache module (running on a Solaris
> machine) that will connect to my Oracle 8.1.7 database. I am using
> some of the C libraries that came with Oracle, but I can't seem to
> connect to the db, which is running on a different machine than
> Apache. I repeatedly get the error: "ORA-01034: ORACLE not
> available."
>
> Here's some of the code:
>
> /* Set some environment variables */
> two_task = (char *)ap_palloc(r->pool,15 +
> strlen(sec->auth_ora8_two_task));
> sprintf(two_task,"TWO_TASK=%s",sec->auth_ora8_two_task);
> putenv(two_task);
>
> /* Try and connect to db. */
> if
(orlon(&lda,hda,(text*)sec->auth_ora8_uid_login,-1,(text*)sec->auth_ora8_pwd _login,-1,0))
> {
> ap_log_error(APLOG_MARK, APLOG_NOTICE, NULL, "Failed to log
> on.");
> text msg[512];
> oerhms(&lda, lda.rc, msg, (sword) sizeof msg);
> msg[strlen(msg) - 1] = 0;
> sprintf(ora8_errstr,"ORA8: Could not connect to Oracle8(%s)
> as %s : %s",(sec->auth_ora8_two_task) ? sec->auth_ora8_two_task : se
> c->auth_ora8_sid ,sec->auth_ora8_uid_login,msg);
> return NULL;
> }
>
> I have tried numerous things for the connect string, but nothing
> works! Some of the things I've tried are:
>
> T:hostname:port:tnsname
> hostname:port:tnsname
> T:hostname:tnsname
> hostname:tnsname
> tnsname
>
> I can connect to Oracle fine through sql*plus on the same machine from
> which I'm trying to connect through C. Does anyone know how the
> connect string should be properly formed?
>
> Thanks, Dave
Received on Fri May 16 2003 - 02:53:12 CDT

Original text of this message

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