ORA-03135: connection lost contact when prepare sql from Perl - oracle

I have a problem about connection to database.I execute command line as below:
$Oracle_Dbh = DBI->connect("dbi:Oracle:$two_task", $Oracle_User, $Oracle_Password,
{ RaiseError => 0 , AutoCommit => 0, PrintError => 0});
$HNDL_TABLE = $Oracle_Dbh->prepare("select * from MMSC40_CDR where rownum<=1");
my $err="";
if(!$HNDL_TABLE){
$err = $Oracle_Dbh->errstr;
$exists = 0;
}
if (!$exists){
print "error: $err";
}
Sometimes, it has a error occurred as below:
"error: ORA-03135: connection lost contact Process ID: 8936 Session ID: 1585 Serial number: 27537 (DBD ERROR: error possibly near <*> indicator at char 11 in 'select * fr<*>om MMSC40_CDR where rownum<=1')"
and DBA checked not have any error in listener log from database.
So if anybody can resolve or find out the cause, please tell me.

I do not have setup to test this, but I guess you are getting this error because you have prepared the query but didn't execute it:
$HNDL_TABLE->execute() or die "Couldn't execute query: $Oracle_Dbh->errstr";
Better to use placeholder ? in query preparation and then execute with value:
$HNDL_TABLE = $Oracle_Dbh->prepare("select * from MMSC40_CDR where rownum<=?");
$HNDL_TABLE->execute(1) or die "Couldn't execute query: $Oracle_Dbh->errstr";

Related

PowerQuery: Getting error info when it's too late to `try`?

Short Version
In PowerQuery, when the error occurs before I'm able to use try, how do I catch an error and get the reason and message strings?
Long Version
In PowerQuery (using Excel if that matters),
OleDb.DataSource(
MyConnectionString,
[Query="SELECT * FROM NonExistingTable"]
)
returns an error. Great. I want that because I'm trying to make a quick and dirty tool that grabs data from multiple tables, but some people don't have access to all tables and who knows what else will happen in the future. However, I want to handle that error so it degrades gracefully, preferably presenting an explanation to the user based on the info within the error.
Therefore, I attempted error handling with try, like so:
try OleDb.DataSource(
MyConnectionString,
[Query="SELECT * FROM NonExistingTable"]
)
and I had expected it to return something like
[
HasError = true,
Error = [
Reason = "OLE DB",
Message = "Invalid object name: 'NonExistingTable'.",
Details = ...
]
]
but instead, what's returned is
[
HasError = false,
Value = Error
]
where Error is an error object containing the information I want.
I had then tried to make a workaround with something like
let
tryRecord = try OleDb.DataSource(MyConnectionString, [Query="SELECT * FROM NonExistingTable"]),
ret = if (tryRecord[HasError]) then
// It's an error
tryRecord
else try
// If Value.Type() doesn't throw an error then tryRecord[Value] isn't an error, so return it.
(if Value.Type(tryRecord[Value]) = null then null else tryRecord)
otherwise
// tryRecord[Value] contains an error!
try error tryRecord[Value]
in
ret
but try error tryRecord[Value] is not unpacking the error object within tryRecord[Value] like I had hoped.
How do I get the reason and message strings from an error object?

Oracle Query in Codeigniter giving ORA-01722 and ORA-01756

Im usually use mysql database in my website, but i trying to learn more about the oracle...
My code working 2days ago, but right now its giving an error message such as ORA-number
this is my database fields
KODE_GUDANG CHAR
GUDANG CHAR
LASTUPDATE CHAR
KODE_UNIT CHAR
NOMER_REKJURNAL CHAR
KODE_GUDANG_KREDIT CHAR
this is my models for query
function getDataOneColumn($getCol, $table, $column, $id) {
return $this->db->query("SELECT $getCol as val FROM $table WHERE $column = $id")->row_array();
}
This is for my controller that giving an error : ORA-01722
$this->data['no_rek'] = ($this->data['no_rek'] =='')?$this->m_dao->getDataOneColumn("NOMER_REKJURNAL","TBL_MASTER_GUDANG","KODE_GUDANG",$this->data['kode_gdg'])['VAL']:$this->data['no_rek'];
and after that i reading the docummentation, its means "You executed a SQL statement that tried to convert a string to a number"
i try to change my code to
$this->data['no_rek'] = ($this->data['no_rek'] =='')?$this->m_dao->getDataOneColumn("NOMER_REKJURNAL","TBL_MASTER_GUDANG","KODE_GUDANG",'"'.$this->data['kode_gdg'])['VAL'].'"':"'".$this->data['no_rek']."'";
this one giving an other ORA error,ORA-01756. its means "You tried to execute a statement that contained a string that was not surrounded by two single quotes"
New Error
Error Number: 1722
ORA-01722: invalid number
SELECT NOMER_REKJURNAL as val FROM TBL_MASTER_GUDANG WHERE KODE_GUDANG = 04
Filename: C:/xampp/htdocs/formula/system/database/DB_driver.php
Line Number: 691
Can somebody tell me why my code getting an error after 2days ?
And
How to solve this error?
thank you
After reading lot of post with ORA error, I can solve my problem.
I just need adding " ' ".$val." ' "
$this->data['no_rek'] = ($this->data['no_rek'] =='')?$this->m_dao->getDataOneColumn("NOMER_REKJURNAL","TBL_MASTER_GUDANG","KODE_GUDANG","'".$this->data['kode_gdg']."'")['VAL']:$this->data['no_rek'];

Perl crashes when script exits after closing database connection

I have a Perl script that opens a ODBC connection to an Oracle database using DBI. Some data is selected, some work is done, no data is actually committed back to the database but I can't tell whether that makes any difference.
In the END block of the script the database is disconnected.
END
{
$$db->disconnect() if defined $$db;
exit 0;
}
Instead of exiting, perl.exe will crash with a fault in an Oracle DLL.
Faulting application name: perl.exe, version: 0.0.0.0, time stamp: 0x5407ac11
Faulting module name: OraOCIICUS19.dll_unloaded, version: 19.6.0.0, time stamp: 0x5e1181b2
Exception code: 0xc0000005
Fault offset: 0x0000000000df18b0
I tried adding a commit() method call before disconnect()ing but that didn't help.
Edit1: $$db is used throughout the script when calling a method on the object. I assume this is because the DBI connection is created within a module method.
my $db = MyModule::OpenDB();
my ( $foo, $bar ) = MyModule::GetFoo( $db );
my $rows = $$db->selectall_arrayref( $SQLStr, { Slice => {} } );
If I try to call a method on a single$ then I get the error Can't call method "commit" on unblessed reference
Edit2: the module that opens the DBI connection does so thusly:
sub OpenDB
{
my ($params) = #_;
my $db = DBI->connect( "dbi:ODBC:Driver={Oracle in instantclient_19_6};Dbq=MYDB", "MYUSER", "MYPASS", {AutoCommit => 0, RaiseError => 1, PrintError => 0, ShowErrorStatement => 1 } ) or croak $DBI::errstr;
$db->{LongReadLen} = 20480;
$db->{LongTruncOk} = 1;
return \$db;
}
I have already tried toggling AutoCommit on and off in case that was the source of any weirdness.
You don't need to disconnect the DB on script-exiting. Perl (DBI) will do this automatically for you when DB-handle gets out of scope.
Usually (if $db is an "un-weakend" reference to the $dbh-handle) this shouldn't have happened before so doing this should not throw any errors, but my guess is that the error stems from some other part of your code.
Anyway - removing the disconnect in the end-block is safe.
$$db is used throughout the script when calling a method on the object. I assume this is because the DBI connection is created within a module method.
Hi,
mhh, if youre really using DBI you maybe should take a look on your module.
thats how I do that:
sub mysql_connect($$$$) {
my ($f_database, $f_host, $f_user, $f_password) = (shift, shift, shift, shift);
my $f_handler = DBI->connect("DBI:mysql:database=$f_database;host=$f_host", $f_user, $f_password, {RaiseError=>0,PrintError=>1});
return $f_handler;
};
my $dbh = mysql_connect($db, $host, $user, $pass);
my $sql = "SELECT X FROM Y.Z";
my $stmt = $dbh->prepare($sql);
my $response = $stmt->execute();
while(my $rowref = $stmt->fetchrow_hashref()){
my %row = %$rowref;
for(keys %row){
print $_." => ".$row{$_}."\n";
}
}
$dbh->disconnect();
EDIT:
Try it out, but change mysql to oracle:
connect('DBI:Oracle:XE',"us01","us01")

determining what ora_type values are supported

#!/usr/bin/perl
use diagnostics;
use DBI;
use DBI qw(:sql_types);
my $AIM_PSWD= $ENV{'AIM_PSWD'};
my $len=length($AIM_PSWD);
my $pwindex1=rindex($AIM_PSWD,'/');
my $pwindex2=rindex($AIM_PSWD,'#');
my $usr = substr($AIM_PSWD,0,$pwindex1);
my $pwd = substr($AIM_PSWD,$pwindex1+1,$pwindex2-($pwindex1+1));
my $db = substr($AIM_PSWD,$pwindex2+1,$len-($pwindex2+1));
my $attr = {AutoCommit => 0};
my $dbh;
my $qryHandle;
my $row;
my $query = "SELECT /*+ index(T_CAPITATION_HIST I_CAPITATION_HIST) */ SAK_CAPITATION FROM AIM.T_CAPITATION_HIST WHERE SAK_CAPITATION = ?";
$dbh = DBI->connect("dbi:Oracle:$db", $usr, $pwd, $attr)
or die "Unable to connect to $db\n";
$qryHandle = $dbh->prepare($query) or die "Unable to prepare query\n";
$qryHandle->bind_param(1, "765756556", {ora_type => SQL_VARCHAR});
$qryHandle->execute() or die "Unable to execute query\n";
if ($row = $qryHandle->fetchrow_hashref())
{
print "query succeeded\n";
}
else
{
print "query failed\n";
}
$qryHandle->finish();
$dbh->disconnect();
exit(0);
Running this produces the error message from the bind_param statement:
Uncaught exception from user code:
Can't bind :p1, ora_type 12 not supported by DBD::Oracle at ./test.pl line 26.
How do I determine what ora_type values are supported?
The available ora_type values are listed at https://metacpan.org/pod/DBD::Oracle#:ora_types and described at https://metacpan.org/pod/DBD::Oracle#ora_type, and must be imported from DBD::Oracle like:
use DBD::Oracle ':ora_types';
If you want to pass a standard SQL type that you imported from DBI :sql_types, just pass it directly as the bind type:
$qryHandle->bind_param(1, "765756556", SQL_VARCHAR);
See https://metacpan.org/pod/DBD::Oracle#bind_param.

Websphere connection pool issue i.e DSRA9110E

LOGGER.debug("Connection Status Disb isClosed = " + conn.isClosed());
// returns true.
crsDisbDetailstmp = DataAccess.getData("select 1 cnt from dual", conn, new String[] {});
crsDisbDetailstmp.first();
LOGGER.debug("crsDisbDetailstmp"+ crsDisbDetailstmp.getString("cnt"));
DataAccess.executeProc("PRC_MCLR_TRNPRCDTL", new String[]{strOrgId, strAccountid,strFixedRate ,strModifiers }, conn);
Exception occured while executing last statement i.e execute procedure.
Exception=com.ibm.websphere.ce.cm.ObjectClosedException: DSRA9110E: Connection is closed.
I search a lot on google it shows this exception is occurred because connection is closed also i checked with conn.isclosed() which return true..
But If connection is closed then how i am able to fire select queries???
Please help me to figure it out as i worked on JBOSS only and first time on Websphere

Resources