john.goor has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,
I have a script that inserts data into a MSSQL using Win32::ADO (dunno if it's relevant)
When run from the command-line it works fine.

The script, however, is used to be called from a cgi. When running the cgi (from the browser) I get "Can't call method "Close" on an undefined value at F:\Apps\Admin\scripts\post_submit.pl line 124."

What makes the script/database connection not to work when called from this cgi?

Note:
The cgi is a cgi that kicks-off the post_submit.pl script using Win32::Process in a separate shell, and immediately redirecting to a logmonitor.cgi, which tails the output of the post_submit.pl script and sends the tail output to the browser. The result is a non-cgi script that is started and not attached to the browser-session.

Oddly enough I have *cgi* scripts using the same database-techniques without a problem.

Need more info? I'd be happy to provide. :-)) Please help, since I'm in deeep trouble if I cannot solve this one..

edit (broquaint): dropped <code> tags and added formatting

Replies are listed 'Best First'.
Re: Puzzled by web
by dave_the_m (Monsignor) on May 24, 2004 at 11:02 UTC
    Call me old-fashioned, but if I had a problem like this, I would see what variable it is that's undefined at line 124, then work my way backwards to discover where it's supposed to get set, and then investigate why it isn't gettting set there. At that point I'd either have found my answer, or be in a more informed position to then ask for help.

    For the record, there are lots of things that will be different when running in a CGI environment as opposed to from the command-line; you may have a different current directory, different environment variables, different stdin/stdout etc, different authorizations,....

      Sorry monks, my fault.

      It took me 3 weeks to find out that the problem had to do with field-length. Line 124 was the closing of a recordset.

      I use Win32::Loginname, which usually is my 8-character uid from the command-line, but run from a browser it is a 25-character IWAM-blablabla IIS uid. This uid will be written to a 8-char field in the database, so an error occurs during the execution of the INSERT statement which finally results in the error of the "Close".

      Edited by Chady -- fixed formatting.

Re: Puzzled by web
by EdwardG (Vicar) on May 24, 2004 at 10:56 UTC

    Check that you have created your DSN as a system DSN, and not per user.

     

Re: Puzzled by web
by jepri (Parson) on May 24, 2004 at 11:02 UTC
    Need more info? I'd be happy to provide. :-))

    Whatever is on line 124 would be a start :)

    Plus any other lines like object creations (or whatever it is you've trying to close).

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.