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

Hey there, forgive me if this is out of the scope of these forums, but it's a real stumper.
I have a script which, for the sake of simplicity, just opens an Excel document. The script is as follows:
#!/usr/bin/perl -w use diagnostics; use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Excel'; my $file = shift(@ARGV); my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32: +:OLE->new('Excel.Application', 'Quit'); my $Book = $Excel->Workbooks->Open($file);
It runs successfully and instantaneously from the command prompt for any Excel document which I pass in. Now, I need to call this script from SQL Server using xp_cmdshell. When called in this way, it runs for about a minute, and the following error is generated:
Win32::OLE(0.1502) error 0x800a03ec in METHOD/PROPERTYGET "Open" +at c:\perl\excel\TestRead.pl line 10
Line 10 is "my $Book = $Excel->Workbooks->Open($file);".
SQL Server and Perl are running on the same machine, which is running Windows Server 2003. xp_cmdshell runs under a user called 'MegaWorker' which has execute permissions on Excel.exe, and full control on the directory with the excel file.
Any ideas? My brain hurts.

Replies are listed 'Best First'.
Re: Problems opening an Excel file...
by jmcnamara (Monsignor) on Feb 09, 2005 at 23:57 UTC

    There are probably a lot of things that can cause this error but one of them is the case where the input file cannot be found. This is turn may be caused by the fact that Excel searches in the user's "My Documents" directory for the file to open and not in the directory that the script is run from.

    If you aren't already doing so, specify the path to the file in Open() to see if it fixes the problem.

    --
    John.

      To complement lmcmanamra's point, 2 other things that can cause this are "/" in the path instead of "\", and opening twice the same file name.
      HTH
      --
      Olivier
        Thanks for your comments. Unfortunately, after some double-checking, none of these seem to be the problem. Here's what the command line looks like:
        c:\perl\bin\perl.exe c:\perl\excel\TestRead.pl "c:\test.xls"
        When I run this from the command line, it works perfectly. When I call it from SQL Server, it fails with the above error.
        I'm especially weirded out by the fact that I'm not getting an error description. That or the description is a series of 4 spaces, which is the crappiest description ever. I blame Microsoft.