Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ActivePerl - Connecting with SQL Server database

Status
Not open for further replies.

Saviour

Programmer
Feb 6, 2001
7
0
0
VE
Hi,

I'm working with ActivePerl and I need to use the SQL Server Database.
I'm using the DBI module and the database connection is ODBC mode.
I'm working with Web pages and I have problems running a program in
the browser.

The program is the following:


Contest.pl
#--------------------------------------------------------------------#
#!/usr/bin/perl -w -I C:\Inetpub\
use DBI;
use Data::Dumper;

&DrawPage();

#--------------------------------------------------------------------#

sub DrawPage() {
my $sBuffer;

$sBuffer = <<__HTML;
<html>
<body>
__HTML

my $moDB;
my $sDSN = &quot;driver={SQL Server};server=B52;database=EIS;
UserID=sa;pwd=''&quot;;
my $sConn = &quot;dbi:ODBC:$sDSN&quot;;

$moDB = DBI->connect($sConn);

if($moDB){
print &quot;Conected !!!!!!!!!!!\n&quot;;
my $sSQL = &quot;select * from entity&quot;;
my @aArray = $moDB->selectall_arrayref($sSQL);
print &Dumper(@aArray);
}else{
print &quot;No conected !!!!!!!!!!&quot;;
}

$moDB->disconnect || die $moDB->errstr;

$sBuffer = <<__HTML;
</body>
</html>
__HTML

} # end of DrawPage


If I run this program in DOS environment: It's works!... but when I run
this program under the browser, the following error message is sended:


CGI Error

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

DBI->connect(driver={SQL Server};server=B52;database=EIS;UserID=sa;pwd='')
failed: [Microsoft][ODBC Driver Manager] Invalid string or buffer length
(SQL-S1090)(DBD: db_login/SQLConnect err=-1) at C:\Inetpub\\cgi-bin\eis\bin\contest.pl line 22
Can't call method &quot;disconnect&quot; on an undefined value at C:\Inetpub\\EISDemo\cgi-bin\eis\bin\contest.pl line 37.
No conected !!!!!!!!!!


Please, Could somebody help me?

Thanks!
 
Could you try changing the line:

$moDB = DBI->connect($sConn);

to:

$moDB = DBI->connect($sConn) or
[tab]die &quot;DBI Error\n$DBI::errstr\n&quot;;

I vaguely remember something like this before -- an apparently healthy script that refused to run as a CGI program. It was, I think, something to do with the setup of the web server rather than the script itself. Sorry to be vague... Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Try putting the Content type in before you print anything else and it should work fine.

print &quot;Content-type: text/html\n\n&quot;;

Tim
develop@embanet.com
 
If a working perl script won't work as a CGI, it's probably because the &quot;web-user&quot; doesn't have the same permissions to a resource that you do.
MikeLacey's suggestion is the first thing to do, apparently

$moDB = DBI->connect($sConn);

isn't working correctly, and that's why there's no $moDB to run the
$moDB->disconnect || die $moDB->errstr;
line perl returns the error. You should put this line within the if statement.

Next thing I usually check is to see if the DSN uses SQL or Windows authentication. Should be set to SQL.

g'luck in yer struggles, chum

-k




 
does anybody know how to set the port number of the SQL server here? please let me know
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top