http://qs321.pair.com?node_id=178120

peacemaker1820 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to connect to MS SQL Server 2000 that is on my NT server. That's the code I have below but when I try to view through a browser it gives me the following error:
"Perhaps the capitalisation of DBD 'ODBC' isn't right. at C:\Inetpub\wwwroot\cgibin\database.pl line 14 HTTP/1.0 200 OK Content-Type: text/html"

print "HTTP/1.0 200 OK\n";
print "Content-Type: text/html\n\n";
print "<HTML><HEAD><TITLE></TITLE></HEAD>\n";
print "<BODY>\n";

use DBI;
use DBD::ODBC;
use CGI;

my ( $server_name, $database, $user_id, $password ) = qw( 'sdp-si.biz' 'SDPSI' 'myusername' 'mypassowrd' );

#Connect the database handle.
$dbh = DBI->connect("DBI:ODBC:$DSN") or die "$DBI::errstr\n";

#Close connection when finished:
$dbh->disconnect;

print "</BODY>\n";
print "</HTML>\n";

I already installed the DBI package, and i read that DBD::ODBC comes with Active Perl already(that's what i have). WHAT SHOULD I DO??? PLEASE HELP MANY THANKS!

Replies are listed 'Best First'.
Re: ODBC and MS SQL Server 2000 Connection
by dws (Chancellor) on Jun 28, 2002 at 20:23 UTC
    I already installed the DBI package, and i read that DBD::ODBC comes with Active Perl already(that's what i have). WHAT SHOULD I DO???

    1. use strict;
    2. $|++; # to unbuffer STDOUT
    3. provide a value for $DSN

    This won't solve your problem, but it'll get you closer.

Re: ODBC and MS SQL Server 2000 Connection
by thunders (Priest) on Jun 28, 2002 at 20:47 UTC
    first off if you are going to use CGI you might as well use it to print the header..
    #!perl -w # ^ you may need that first line # my local Apache server does... use DBI; use CGI qw/:standard/; print header;

    Also take out use DBD::ODBC; it's nota module you need to import. it's a driver. generally just use DBI. You may Need to Set up a "System DSN" connection to the SQL Server in Conrol Panel->Data Sources(ODBC). and you will have to declare a value for $DSN. Also make sure that the driver for SQL Server is in you list of Drivers in the Same ODBC Panel

Re: ODBC and MS SQL Server 2000 Connection
by peacemaker1820 (Pilgrim) on Jun 28, 2002 at 21:10 UTC
    print "HTTP/1.0 200 OK\n";
    print "Content-Type: text/html\n\n";
    print "<HTML><HEAD><TITLE></TITLE></HEAD>\n";
    print "<BODY>\n";
    
    use DBI;
    #use DBD::ODBC;
    use CGI;
    
    my ( $data_source, $database, $user_id, $password ) = qw( sdp-si.biz SDPSI username password   );
    my $DSN = "driver={SQL Server};Server=$data_source;Database=$database;UID=$user_id;PWD=$password";
    #Connect the database handle.
    $dbh = DBI->connect("DBI:ODBC:$DSN") or die "$DBI::errstr\n";
    
    print "hello there";
    #Close connection when finished:
    $dbh->disconnect;
    print "hello there";
    print "</BODY>\n";
    print "</HTML>\n";