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

I have a pretty plain vanilla Perl script where I try to connect to a FoxPro database via Microsoft Visual FoxPro driver. My Foxpro server is on a different machine than my web server, where my Perl script is. When I try to run it, I get "Cannot Connect." When I put the Foxpro data on the same server as my Perl script, then it works. It also seems to work from the DOS command line. Only when I am running the Perl script from my browser do I get the "Cannot Connect" message. My FoxPro DSN uses a UNC path to point to the FoxPro data. I can read and write to this data server from my web server, having browsed to it and entered the necessary network user id and password. Any suggestions would be helpful... thanks, bill chicago,il

Replies are listed 'Best First'.
Re: ODBC Cannot Connect
by ptum (Priest) on Feb 01, 2006 at 01:23 UTC

    If you are using Apache as your webserver, you need to pass environment variables explicitly using the PassEnv directive.


    No good deed goes unpunished. -- (attributed to) Oscar Wilde
      I am using Apache as my web server. Can you give a little more info on this? Do I pass the variables in the Perl script or the HTML that calls the script? And which environment variables do I pass? Is there perhaps a sample script of this that I can download and look at? Right now I'm thinking the cause of this problem as that my Perl script is being run as another user and does not have network security rights over the network. thanks, bill

      I'm not at work, so I'll have to punt a little -- I'll fill in more detail when I get back in tomorrow. Basically, I think you will want to modify your httpd.conf file to explicitly pass the environment variables that you want to be available when you execute programs as the webuser (also defined in your httpd.conf). The link to PassEnv that I specified above shows the edited portion of the httpd.conf. Once you've changed httpd.conf, then you need to stop and restart Apache.

      Hmmm. Now that I look more closely at your original question, I see that you are on a Windows platform -- my experience is all on the Unix side. I had to look up what a Universal Naming Convention (UNC) path was. All this is to say that I may be leading you up a blind alley. If so, please accept my apologies, and perhaps someone who actually knows how to solve this problem will respond. :)

      Update: I modified Apache's httpd.conf file with the following Directory tag, passing $ENV{LD_LIBRARY_PATH} from webuser's profile to any script executed by the webserver:

      <Directory /> Options FollowSymLinks AllowOverride None PassEnv LD_LIBRARY_PATH PATH </Directory>

      Not sure if this will help you.

Re: ODBC Cannot Connect
by strat (Canon) on Feb 01, 2006 at 09:25 UTC

    sounds like the webserver runs the script as another user than the shell, i.e. too little rights on the UNC share for that web user. If you use Internet Information server, the script normally runs as IUSR_$servername. Or if you use a connection created by Window's ODBC-Manager, you have to use a System-DSN, not a User-DSN

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

      I think you may be partially right on this issue. However, I have setup the ODBC DSN as a System DSN for Microsoft FoxPro. When I manually go into Excel and try to open the database through the ODBC DSN, I can open it fine. But when the Perl script begins, I get "Cannot Connect." When I copy the database to the same web server machine, I can also open it locally through the ODBC driver with no problem. I am running this on an Apache web server. Is there perhaps a default User name that the apache web server uses when attempting to connect over the network? thanks, bill
Re: ODBC Cannot Connect
by kwaping (Priest) on Jan 31, 2006 at 23:31 UTC
    Sounds like an environment variable might be missing in your web server environment. Does this give you any ideas?