Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Pro*C Connections
Hello,
IMHO selecting from v$database for the purpose of doing "database whoami" is
slightly
incorrect. It will not work if you have same instance/database names on
multiple
machines, like 'ORA7' on "sun01", "ORA7" on "sun02", etc. If your instance
naming
is like this, you'll have to get the actual hostname and append it to the
instance name.
I used to use a view and accompanying public synonym/grant:
create view whoami as
select 'You are connected to ' || instance_name || ' on ' || machine "Who am
i"
from v$instance, v$session where type = 'BACKGROUND' and program like
'%PMON%';
This was created on all databases. This was very handy, because
if are in SQLPlus connected via SQLNet from another host, "!whoami" will not
give you the host where the database is. My sins, I did a couple of mistakes
because of this, then created this view.
This is the way to get the information from the DB.
How to get information at the client side, in Pro*C, not using the database
calls?
Obviously, the client side should know this information before it successfully
connects.
This connection management is performed by TNS, and the user process
communicates
with TNS by means of "service names", like "ttr.acme.com".
To my information Oracle has not yet created the API for service names
management.
This makes me think there's no documented way to get this information in
Pro*C, though
it can still be stored in structures like LDA/HDA, or can be obtained
accessing
TNSNAMES.ORA directly.
Karen Abgarian.
Dan Benwell wrote:
> you could query the v$database view to determine the oracle sid.
> Dan
> Chris Angus <chris.angus_at_acsol.freeserve.com> wrote in message
> news:7pknr5$olv$1_at_news6.svr.pol.co.uk...
> > Hi,
> > In Pro*C Is it possible to determine the database name from your current
> > connection? or to say all following sql now applies to database X?
> >
> > The sort of code I've got is
> >
> > void fn() {
> > connect();
> > do_work();
> > disconnect();
> > }
> >
> > what I need to do is have the connection persist but the do_work is
> > a load of legacy code and there's a chance that the connection will be
> > swiped if I just leave it connected.
> >
> > is there any way of saying
> >
> > void fn() {
> > if (current connection not what I think it is)
> > connect();
> > do_work();
> > }
> >
> > or ideally
> >
> > void fn() {
> > if (first time) connect() and call connection C;
> > use C;
> > do_work();
> > stop using C:
> > }
> >
> > in Pro*C so that the do_work function does not have to be filled with AT
> > clauses?
> >
> > Many thanks in advance for any help
> >
> > Chris
> >
> >
> >
> >
> >
> >
> >
> >
> >
Received on Thu Aug 26 1999 - 11:31:11 CDT
![]() |
![]() |