in reply to Re: Identify host connected to in DBD::Oracle connection?
in thread Identify host connected to in DBD::Oracle connection?

Hi.

print "Name: $dbh->{Name}\n"; returns Name: prod_01 which is the database name.

I'm hoping I might be able to determine the hostname used for the connection (which one of the nine hosts listed in the tnsnames.ora definition was used for this connection).

Replies are listed 'Best First'.
Re^3: Identify host connected to in DBD::Oracle connection?
by kennethk (Abbot) on Sep 28, 2009 at 17:18 UTC
    That's what I get for reading too fast. How about trying a get_info call on SQL_SERVER_NAME? I've verified the following against an Oracle database I have access to, but not in a multiple hosts/load balance context.

    #!/usr/bin/perl use strict; use warnings; use DBI; use DBI::Const::GetInfoType; my $_db_name = 'host'; my $_db_user = 'name'; my $_db_pass = 'password'; my @_dbi_path = ("dbi:Oracle:$_db_name",$_db_user,$_db_pass); my $handle = DBI->connect( @_dbi_path, { PrintError => 1, RaiseError => 0, AutoCommit => 0 } ); #print join "\n", sort keys %GetInfoType; print $handle->get_info($GetInfoType{SQL_SERVER_NAME});

    See DBI::Const::GetInfoType and get_info in DBI.

    Update: Still no dice -> in DBD::Oracle, this is just a synonym for $handle->{Name}, as is SQL_DATA_SOURCE_NAME.