problem with DBD::ODBC

D

dima

Hello all
I have one problem with DBI module.
This is the description of my problem:
I try to prepare and execute one sql statement ($sql1) and it's ok, but
when I try to prepare and execute second sql statement ($sql2) and not
finish first I get this error:
DBD::ODBC::db prepare failed: (DBD: st_prepare/SQLPrepare err=-1) at
line ...
Can't prepare statement: (DBD: st_prepare/SQLPrepare err=-1) at line
....

Can someone help my?

This is my script:

use strict;
use DBI;

my $dbh;
my $msuser = 'test';
my $mspasswd = 'test';
$dbh = DBI->connect('dbi:ODBC:mssql', $msuser, $mspasswd);

my $sql1 = qq{SELECT * FROM CallDetailRecord;};

my $sql2 = qq{SELECT * FROM CallDetailRecord;};

my $sth1 = $dbh->prepare($sql1) or die("Can't prepare statement:
$DBI::errstr");
my $rc1 = $sth1->execute() or die("Can't execute statement:
$DBI::errstr");
#$sth1->finish();
my $sth2 = $dbh->prepare($sql2) or die("Can't prepare statement:
$DBI::errstr");
my $rc2 = $sth2->execute() or die("Can't execute statement:
$DBI::errstr");
#$sth2->finish();
$dbh->disconnect if ($dbh);
 
M

Mark Clements

Hello all
I have one problem with DBI module.
This is the description of my problem:
I try to prepare and execute one sql statement ($sql1) and it's ok, but
when I try to prepare and execute second sql statement ($sql2) and not
finish first I get this error:
DBD::ODBC::db prepare failed: (DBD: st_prepare/SQLPrepare err=-1) at
line ...
Can't prepare statement: (DBD: st_prepare/SQLPrepare err=-1) at line
...

Can someone help my?

This is my script:

use strict;
use DBI;

my $dbh;
my $msuser = 'test';
my $mspasswd = 'test';
$dbh = DBI->connect('dbi:ODBC:mssql', $msuser, $mspasswd);

my $sql1 = qq{SELECT * FROM CallDetailRecord;};

my $sql2 = qq{SELECT * FROM CallDetailRecord;};

I'd guess you have to remove the semi-colon from each string.

Mark
 
K

ko

Hello all
I have one problem with DBI module.
This is the description of my problem:
I try to prepare and execute one sql statement ($sql1) and it's ok, but
when I try to prepare and execute second sql statement ($sql2) and not
finish first I get this error:
DBD::ODBC::db prepare failed: (DBD: st_prepare/SQLPrepare err=-1) at
line ...
Can't prepare statement: (DBD: st_prepare/SQLPrepare err=-1) at line
...

Can someone help my?

This is my script:

use strict;
use DBI;

my $dbh;
my $msuser = 'test';
my $mspasswd = 'test';
$dbh = DBI->connect('dbi:ODBC:mssql', $msuser, $mspasswd);

my $sql1 = qq{SELECT * FROM CallDetailRecord;};

my $sql2 = qq{SELECT * FROM CallDetailRecord;};

my $sth1 = $dbh->prepare($sql1) or die("Can't prepare statement:
$DBI::errstr");
my $rc1 = $sth1->execute() or die("Can't execute statement:
$DBI::errstr");
#$sth1->finish();
my $sth2 = $dbh->prepare($sql2) or die("Can't prepare statement:
$DBI::errstr");
my $rc2 = $sth2->execute() or die("Can't execute statement:
$DBI::errstr");
#$sth2->finish();
$dbh->disconnect if ($dbh);

Set the odbc_cursortype (it's in the DBD::ODBC documentation) attribute
in the \%attr parameter. You should be using \%attr anyway - you can
leave out all the "or die..." statements. Something like:

my $dbh = DBI->connect($data_source, $user, $pass, {
RaiseError => 1,
PrintError => 0,
AutoCommit => 1,
odbc_cursortype => 2
});

HTH - keith
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top