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

Ok, I have IIS running on my local machine and I know it works, I have sql server running on a remote machine and I know it works, put when I bring them together with perl I get nothing please help.

This Works
<html> <head> <title>test page</title> </head> <body> <h1>Hello World!!!</h1> </body> </html>
And This Works
#!/usr/bin/perl # dbtest.pl use warnings; use strict; use DBI; my ($CDS, $UPDATE, $name, $type, $len, $sqlquery); $CDS=DBI->connect('DBI:ODBC:claudonntUPDATE', 'xxxx', 'xxxx') || die "error opening database: $DBI::errstr\n"; # sql query ******************************************* $sqlquery=$CDS->prepare(" SELECT catid, description, count (*) FROM cds_prod, cds_cctxx WHERE catid = id GROUP BY catid, description ORDER BY catid;") || die "Prepare failed: $DBI::errstr\n"; $sqlquery->execute() || die "couldn't execute query: $DBI::errstr\n"; while (($name, $type, $len) = $sqlquery->fetchrow_array) { print "$name","\t","$type", "\t","$len\n"; } $sqlquery ->finish(); $CDS->disconnect || die "failed to disconnect\n";
BUT THIS DOSEN'T - it is being called as http://localhost/scripts/dbtestonline.pl - I think it is failing at $CDS=DBI->connect... but I don't know why
#!/usr/bin/perl # dbtest.pl use warnings; use strict; use DBI; print "Content-type: text/html\n\n"; my ($CDS, $UPDATE, $name, $type, $len, $sqlquery); print " <html> <head> <title>dbtest </title> </head> <body>"; $CDS=DBI->connect('DBI:ODBC:claudonntUPDATE', 'xxx', 'xxx') || die "error opening database: $DBI::errstr\n"; # sql query ******************************************* $sqlquery=$CDS->prepare(" SELECT catid, description, count (*) FROM cds_prod, cds_cctxx WHERE catid = id GROUP BY catid, description ORDER BY catid;") || die "Prepare failed: $DBI::errstr\n"; $sqlquery->execute() || die "couldn't execute query: $DBI::errstr\n"; print "<center><table Border=1>"; while (($name, $type, $len) = $sqlquery->fetchrow_array) { print "<tr><td>$name</td> <tr>$type</td> <tr>$len</td></tr>"; } print "</table></center></body><html>"; $sqlquery ->finish(); $CDS->disconnect || die "failed to disconnect\n";

Replies are listed 'Best First'.
Re: perl, IIS, and sql Server help
by sierrathedog04 (Hermit) on Mar 30, 2001 at 01:19 UTC
    What kind of authentication are you using? Depending on how you have IIS set up, your scripts may be running as a default web user with a name like IIS_user or something like that.

    Have you run your script from the command line as the default web user? Does it still work when you do so?

    Until I wised up, I often had a problem with scripts which ran from the command line but not as a web program. In every case I can recall, the problem was that the default web user lacked the rights to run the script correctly. When I fixed the rights issue the problem went away.

Re: perl, IIS, and sql Server help
by esolm (Acolyte) on Mar 30, 2001 at 00:33 UTC
    OK, the code works at the command line, and the output is exactly what I want. But it still does not work when called from a browser. Here is the source I get from the browser
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=windows-1252 +"></HEAD> <BODY></BODY></HTML>


    and here is what I get at the command line
    Content-type: text/html <html> <head> <title>dbtest </title> </head> <body><center><table Border=1><tr><td>AA</td> <td>Desktop / Deskside</td> <td>2660</td></tr><tr><td>AB</td> <td>Laptop</td> <td>432</td></tr><tr><td>AC</td> <td>Handheld / PDA</td> <td>18</td></tr><tr><td>AD</td> <td>Processor Upgrade</td> <td>6</td></tr><tr><td>AE</td> <td>Mainboard</td> <td>30</td></tr><tr><td>AF</td> <td>System Cabinet</td> <td>27</td></tr><tr><td>AG</td> <td>UPS / Power Device</td> <td>138</td></tr><tr><td>AH</td> <td>System / Power Cable</td> <td>20</td></tr><tr><td>AI</td> <td>IO Adapter / Connectivity</td> <td>6</td></tr><tr><td>AJ</td> <td>System Accessory</td> <td>33</td></tr><tr><td>AK</td> <td>System Service / Support</td> <td>6</td></tr><tr><td>BA</td> <td>Random Access Memory</td> <td>70</td></tr><tr><td>BC</td> <td>Cache Memory</td> <td>2</td></tr><tr><td>BD</td> <td>Flash Memory</td> <td>77</td></tr><tr><td>BE</td> <td>Read-Only Memory</td> <td>1</td></tr><tr><td>CA</td> <td>Hard Disk Drive</td> <td>82</td></tr><tr><td>CC</td> <td>Removable Disk Drive</td> <td>76</td></tr><tr><td>CD</td> <td>Removable Tape Drive</td> <td>123</td></tr><tr><td>CE</td> <td>Network Storage</td> <td>13</td></tr><tr><td>CF</td> <td>Removable Media</td> <td>7</td></tr><tr><td>CG</td> <td>Storage Adapter</td> <td>22</td></tr><tr><td>CH</td> <td>Storage Cable</td> <td>2</td></tr><tr><td>CI</td> <td>Storage Cabinet</td> <td>6</td></tr><tr><td>CJ</td> <td>Storage Accessory</td> <td>38</td></tr><tr><td>DA</td> <td>Key-Entry Device</td> <td>3</td></tr><tr><td>DB</td> <td>Pointing Device</td> <td>17</td></tr><tr><td>DC</td> <td>Game Controller</td> <td>5</td></tr><tr><td>DD</td> <td>Scanner</td> <td>18</td></tr><tr><td>DG</td> <td>Video Input</td> <td>9</td></tr><tr><td>DI</td> <td>Input Cable</td> <td>16</td></tr><tr><td>DJ</td> <td>Input Accessory</td> <td>3</td></tr><tr><td>EA</td> <td>Monitor Desktop</td> <td>25</td></tr><tr><td>EC</td> <td>Projector / Panel</td> <td>7</td></tr><tr><td>ED</td> <td>Printer / Plotter</td> <td>130</td></tr><tr><td>EE</td> <td>Audio Output</td> <td>2</td></tr><tr><td>EF</td> <td>Video Adapter</td> <td>2</td></tr><tr><td>EG</td> <td>Audio Adapter</td> <td>1</td></tr><tr><td>EH</td> <td>Output Cable</td> <td>8</td></tr><tr><td>EI</td> <td>Printer Consumables</td> <td>9</td></tr><tr><td>EJ</td> <td>Output Accessory</td> <td>9</td></tr><tr><td>EK</td> <td>Output Service / Support</td> <td>3</td></tr><tr><td>FA</td> <td>Modem / Communication</td> <td>116</td></tr><tr><td>FB</td> <td>Communication Device</td> <td>3</td></tr><tr><td>FC</td> <td>Concentrator / Multiplexer</td> <td>54</td></tr><tr><td>FD</td> <td>Repeater / Transceiver</td> <td>19</td></tr><tr><td>FE</td> <td>Hub / Switch</td> <td>121</td></tr><tr><td>FF</td> <td>Bridge / Router</td> <td>95</td></tr><tr><td>FG</td> <td>Network Device</td> <td>206</td></tr><tr><td>FH</td> <td>Network Adapter</td> <td>87</td></tr><tr><td>FI</td> <td>Network Cable</td> <td>512</td></tr><tr><td>FJ</td> <td>Network Accessory</td> <td>11</td></tr><tr><td>FK</td> <td>Network Service / Support</td> <td>30</td></tr><tr><td>GA</td> <td>Operating System</td> <td>25</td></tr><tr><td>GB</td> <td>Application</td> <td>2859</td></tr><tr><td>GC</td> <td>Software Service / Support</td> <td>2</td></tr><tr><td>HA</td> <td>Reference Material</td> <td>2</td></tr><tr><td>JD</td> <td>Camcorder</td> <td>27</td></tr><tr><td>KA</td> <td>Home Audio</td> <td>25</td></tr><tr><td>KB</td> <td>Portable Audio</td> <td>17</td></tr><tr><td>PB</td> <td>Cellular / PCS</td> <td>1</td></tr></table></center></body><html>
Re: perl, IIS, and sql Server help
by how do i know if the string is regular expression (Initiate) on Mar 29, 2001 at 22:35 UTC
    What is displayed in the browser when you access this page?
    Have you you tried running the "non-working" script from the command prompt?
    I don't know a lot about IIS, but do you have it set up to execute .pl files and all that wacky stuff?

    - FrankG

      IIS on my local machine is set up to execute .pl files as I note with the hello world! script written to display on my webserver in html.

      As for the non_working script the browser shows the title as defined at <title>dbtest </title> but then shows a blank screen.

      I know the basic database query works because the second code non html works from the command line. So the problem is that the third code does not work when called from the url.
        Ok... I see a problem.
        In your code in the third script:
        while (($name, $type, $len) = $sqlquery->fetchrow_array) { print "<tr><td>$name</td> <tr>$type</td> <tr>$len</td></tr>"; }
        A couple of those <tr>'s should be <td>'s.
        Change it to this:
        while (($name, $type, $len) = $sqlquery->fetchrow_array) { print "<tr><td>$name</td> <td>$type</td> <td>$len</td></tr>"; }

        And just as a rule, when I run into problems like this, the first thing I usually do is run the script from the command line. It often helps you figure out what is and is not going on.

        - FrankG