DBI connect('db_local','',...) failed: at...

From: Lee Roper (leeroper_at_photomd.net)
Date: 04/28/04


Date: 28 Apr 2004 14:46:42 -0700

Hi, folks.

I'm a newbie, but I've done my homework on this
(googed the newsgroups, docs, etc.), yet can't find
an answer anywhere else that's solved this for me.

So, here I am. Please be kind; I'm a gentle soul. :)

I've tried several different approaches, e.g., using
Win32::ODBC, various connection strings (with user and
password included), and such, but I simply haven't been
able to obtain a connection to SQL Server -- or MS
Access (*.mdb,) for that matter -- via cgi.

The script works fine from the comman prompt, just
not in a browser (and, yes, I've set up a system, not
user, level DNS). I've gotten other cgi scripts to
work with my setup, just not when trying to connect to
a database.

*Any* help will be greatly appreciated.

Lee Roper...

The error msg is as follows:

CGI Error
The specified CGI application misbehaved by not returning
a complete set of HTTP headers. The headers it did return are:

DBI connect('db_local','',...) failed: at F:\Web_Dev\Perl\mssql.pl line 10
===============================================

Here's my environment, all running on my personal localhost.

===============================================
perl5 (revision 5 version 6 subversion 1) configuration:
IIS 5.0, Win2k Server, SQL Server 2k, perl build 638

=====================================================

And, below is the script, sans line numbers:
(note that there is no password associated with the DNS or database)

=============================
#!C:\perl\bin\perl.exe
use CGI;
use warnings;
use DBI;
use DBD::ODBC;

# connect to database

$dbh = DBI->connect('DBI:ODBC:db_local','xxxyyy','', {RaiseError=>1}) or
problem('Cannot connect to database');

if ($dbh)
{
 $dbh->errstr;

  # set data size and ok to truncate
  $dbh->{LongReadLen} = 10000;
  $dbh->{LongTrun***} = 1;

  my $sql;
  $sql = "SELECT * FROM Pennsylvania_Zip_Codes Where City='Philadelphia'";
  $sth = $dbh->prepare($sql);
  $sth->execute;

  while(@values = $sth->fetchrow_array)
  {
    print "$values[1] - $values[0]\n";
  }

    # disconnect

  $sth->finish;
  $dbh->disconnect;
}
else
{
  print "Database connection failed.";
}


Quantcast