MS SQL errors in my script

MS SQL errors in my script

am 21.05.2007 20:00:02 von jordanmueller

------=_Part_44601_18782032.1179770402648
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hello,

I am trying to write a script that connects to a remote MS SQL database.
I have set up dsn on my server before and have no problem connecting. But
something is working this time.

I am pasting my script and the error messages below. If nay one has any
experience with MS SQL Errors that would be very helpful.

++++++++++++++++++++++++++++++++++++++++++++++++++
DBI Script
++++++++++++++++++++++++++++++++++++++++++++++++
my $data_source = 'EXAMPLE';

my $dbh = DBI->connect("dbi:ODBC:$data_source", 'test',
'password') || die "unable to connect: $DBI::errstr";


my $statement = 'SELECT * FROM Patients';


my $sth = $dbh->prepare($statement) ||
die "unable to prepare $statement: $DBI::errstr";

$sth->execute() || die "$DBI::errstr";

my $data = $sth->fetchrow_arrayref();

$dbh->disconnect();

++++++++++++++++++++++++++++++++++++++++++++
ERRORS
+++++++++++++++++++++++++++++++++++++++++++++

[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name
'Patients'. (SQL-42S02)
[Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be
prepared. (SQL-42000)(DBD: st_execute/SQLExecute err=-1) at rcmp.pl line 32.



+++++++++++++++++++++++++++++++++++++++++++++

The connection seems to be fine, I don't know what to do about SQL Server
errors.

Thank you,

Jordan

------=_Part_44601_18782032.1179770402648--

Re: MS SQL errors in my script

am 21.05.2007 20:41:27 von Jenda

From: "Jordan Mueller"
> Hello,
>
> I am trying to write a script that connects to a remote MS SQL database.
> I have set up dsn on my server before and have no problem connecting. But
> something is working this time.
>
> I am pasting my script and the error messages below. If nay one has any
> experience with MS SQL Errors that would be very helpful.
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++
> DBI Script
> ++++++++++++++++++++++++++++++++++++++++++++++++
> my $data_source = 'EXAMPLE';
>
> my $dbh = DBI->connect("dbi:ODBC:$data_source", 'test',
> 'password') || die "unable to connect: $DBI::errstr";
>
>
> my $statement = 'SELECT * FROM Patients';
>
> ...
> ++++++++++++++++++++++++++++++++++++++++++++
> ERRORS
> +++++++++++++++++++++++++++++++++++++++++++++
>
> [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name
> 'Patients'. (SQL-42S02)
> [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be
> prepared. (SQL-42000)(DBD: st_execute/SQLExecute err=-1) at rcmp.pl line 32.
>
> +++++++++++++++++++++++++++++++++++++++++++++
>
> The connection seems to be fine, I don't know what to do about SQL Server
> errors.

There is no 'Patients' table in the current database. Either the
table is named differently or you are not in the database you think
you are. Try to review the ODBC data source whether it does specify
the right database to use or add a

$dbh->do('use TheDatabaseName');

after the constructor;

HTH, Jenda
===== Jenda@Krynicky.cz === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery