Link to home
Start Free TrialLog in
Avatar of Lee Redhead
Lee RedheadFlag for United Kingdom of Great Britain and Northern Ireland

asked on

HTTP Error 502.2 - Bad Gateway in Perl CGI script when accessing SQL Stored Proc with Parameters

Hello,

I am currently involved in a project that requires me to send some data from a SQL database in a Perl script file.

Having never delt with Perl this is proving slightly problematic as I don't really know what I am doing but I am figuring it out slowly.

So far I have managed to get the connection to work correctly and can run basic SELECT commands using the URL parameters. I have also managed to get a SQL Stored Proc to run fine with out any problems that contained a simple SELECT * FROM Table statement.

The problem I am having now is adding the Parameters to the file as I keep getting a 502.2 error and I can't work out why.

I have attached a code snippet below and hopefully it is something glaringly obvious but as I have no Perl experience I have no idea. I have tried using some example in tutorials but I keep getting the error.

Lee
#!/usr/bin/perl
use CGI qw(param);
my $Model = param("Model");
 
print "Content-type: text/html\n\n";
 
print "<html><body>";
 
print "<br><p><center><h2>Data Return (CGI)</h2></center></p>";
 
print "<p>Start Of Data for Model: $Model</p>";
 
print "<p>";
 
use strict;
use DBI;
my $db_user = "user";
my $db_pass = "password";
if (my $dbh = DBI-> connect('dbi:ODBC:perltest',$db_user,$db_pass)) {
 
 
   my $sql = "declare @Model char(6) exec mtkSP_PerlTest @Model =123456";
 
   if (my $sth = $dbh->prepare($sql)) {
 
       if ($sth->execute()) {
 
           while (my @row = $sth->fetchrow_array) {
 
               print join(", ", @row), "!";
           }
       }
       else {
 
           print "Execute failed : ".$dbh->errstr;
       }
   }
   else {
 
       print "Prepare failed : ".$dbh->errstr;
   }
}
else {
 
   print "Failed to login";
 
}
 
print "</p>";
 
print "<p>End Of Data</p>";
print "</body></html>\n";
 
exit;

Open in new window

SOLUTION
Avatar of Adam314
Adam314

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lee Redhead

ASKER

mrjoltcola - That worked perfectly, brought back the data as expected.

adam314 -Even though it didn't answer the question being able to see what has gone wrong is really useful.