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

I have a simple Perl script that uses an ODBC DSN to connect across a network to a database server and do a query. Yet it fails every time, giving "CANNOT CONNECT." The DSN works when I point it to the same database stored locally. I can also go to Excel and load the same database across the network using the same ODBC. So the reason appears to be that, running the CGI script from Perl, that it is running as a shell and doesn't have login security authentication (even though I can browse manally). So I believe, in order for this to work, i need to know eihter: 1. What is the name of the Username that the Perl script will attempt to log onto, so that I can give it access rights? or 2. Can I have the script log onto the network drive first before connecting and get authentication that way? much thanks, bill rosman
  • Comment on Logging onto other Domain PC from CGI Shell

Replies are listed 'Best First'.
Re: Logging onto other Domain PC from CGI Shell
by Corion (Patriarch) on Feb 03, 2006 at 07:37 UTC

    You don't tell us what webserver you are using, but from the problem you have, I guess it is IIS. Under IIS, all CGI scripts run as the SYSTEM user or the IIS user, however it's called. Neither have privileges to access network shares, and it would be a bad security decision to give them those privileges.

    I can only recommend you to get a real database instead of trying to connect via SMB shares. You could look at DBD::Proxy and have it running on the other machine and connect from your script on the server to the proxy, or you could run DBD::Proxy on your webserver as a different user.

      I'm sorry i should have mentioned we are using Apache web server. Does apache use a default system user name? what are SMB shares? thanks, bill

        I think that you configure the user Apache uses either via the httpd.conf or, if Apache runs as a service, in the service manager.

        SMB shares is another word for "network shares". SMB is the protocol that Windows uses.

Re: Logging onto other Domain PC from CGI Shell
by strat (Canon) on Feb 03, 2006 at 09:27 UTC

    That sounds like the cgi script is run by a different user than the shell script

    If you use the ODBC Manager, try to use a SystemDSN instead of a userDSN, then all users should be able to access it. Or use perl to create the UserDSN for that user:

    #! perl use strict; use Win32::ODBC; my $dsn = "mydsn"; # name of the DSN in ODBC manager my $dsnDescription = "testdsn"; my $sqlServer = "mymachine"; # Hostname of the SQL-Server my $database = "mydb"; # Name of Database my $uid = ""; # userId my $password = ""; # password if (Win32::ODBC::ConfigDSN ( ODBC_ADD_DSN, "SQL Server", # or name of ODBC ( "DSN=$dsn", "DESCRIPTION=$dsnDescription", "SERVER=$sqlServer", "DATABASE=$database", "UID=$uid", "PWD=$password", ) ) ){ print ("DSN $dsn sucessfully created\n"); } else { die ("ERROR: couldn't create DSN '$dsn': ".Win32::ODBC::Error()); }
    If you need special values you don't know, create the DSN with the ODBC manager and then have a look at your registry: * System-DSN: HKEY_LOCAL_MACHINE\Software\ODBC * User-DSN: HKEY_CURRENT_USER\Software\ODBC there you will find your DSNs with its properties, e.g.
    "DATABASE=$database", "UID=$uid", "PWD=$password", "Trusted_Connection=Yes",

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