Hi all,

To anyone who had been using Perl DBI and Oracle, can you please confirm if
connection by SYSDBA works or doesn't?

I currently have the following DBI / DBD installed on this problem:

DBI Version : 1.43
DBD Version : 1.15

Unfortunately, am not the SA so can't just install the latest module, i.e.
if the issue is version related. Got no test box to test this on either, so
am a bit stuff, hopefully someone from the group had tried this on.

If anyone have the latest DBI and DBD version and uses Oracle, can you
please try if connection by SYSDBA, without supplying username and password
works or not?

The example that I got from CPAN that am trying out which supposedly should
work is as below:

This one gives segmentation fault:

#!/usr/bin/perl

use DBI;
use DBD::Oracle qw(:ora_session_modes);

print $DBI::VERSION,"\n";               # this prints the DBI version

$dsn = "dbi:Oracle:";       # no dbname here
$ENV{ORACLE_SID} = "test";  # set ORACLE_SID as needed
delete $ENV{TWO_TASK};      # make sure TWO_TASK isn't set
$dbh = DBI->connect($dsn, "", "", { ora_session_mode => ORA_SYSDBA }); # no
need to supply username and password
my $sth = $dbh->prepare("alter session set nls_date_format = 'DD-MON-YYYY
HH24:MI:SS'");
$sth->execute();
my $sth = $dbh->prepare("select 'Today is ' || sysdate from dual");
$sth->execute();
while (my ($sysdate) = $sth->fetchrow_array()) {
    print $sysdate, "\n";
}
$sth->finish();

exit 0;

FYI, connection by sqlplus "/as sysdba" works alright and am testing this
locally on the server where the Oracle database is installed. Oracle version
is 10g at the moment but I will be needing this script to work from Oracle9.

Using the following code below where I include a username and password, this
works alright, so that more or less confirm that the DBI module is alright.
I want to get the SYSDBA connection working so I do not have to specify the
username and password when the script is run.

#!/usr/bin/perl

use DBI;

$dbh = DBI->connect('dbi:Oracle:host=localhost;sid=test;port=1521',
'system', 'correct_pass');
my $sth = $dbh->prepare("alter session set nls_date_format = 'DD-MON-YYYY
HH24:MI:SS'");
$sth->execute();
my $sth = $dbh->prepare("select 'Today is ' || sysdate from dual");
$sth->execute();
while (my ($sysdate) = $sth->fetchrow_array()) {
    print $sysdate, "\n";
}
$sth->finish();

exit 0;

Basically, if possible, I just want to confirm from any Oracle DBI experts
that it is possible to connect using SYSDBA without suppling a username and
password.

BTW, forgive my ignorance, when do I need to use and not to use DBD. If you
look at the example above, the second set of code where I supply the
username and password does not require use DBD. Does that mean I need to use
DBD only if it is database specific, on this instance, Oracle?

Any feedback will be very much appreciated

Reply via email to