Perl CGI script using Win::ODBC module - failed login on

B

byoukstetter

Ok I have an issue with a CGI script that I have written in Perl using
the Win::ODBC module for db access. I have a System DSN that I have
setup on the server and I want the script to use that ODBC DSN for
security reasons. The bit something like:

$DSN = "vrs";
if (!($db = new Win32::ODBC($DSN))){
print "Content-type: text/html\n\n";
print "Error connecting to $DSN\n";
print "Error: " . Win32::ODBC::Error() . "\n";
exit;
}
..
..
..

From all the examples I've seen, this work. However, when the script
is run I always get an error like: "the user '(null)' is not
associated with a trusted SQL server connection".

If I change the script to:
$DSN = "vrs";
if (!($db = new Win32::ODBC("dsn=vrs; uid=xx; pwd=blah;"))){
print "Content-type: text/html\n\n";
print "Error connecting to $DSN\n";
print "Error: " . Win32::ODBC::Error() . "\n";
exit;
}

The new Win32::ODBC object is created with out a problem, but I want to
encapsulate the login credentials into the DSN.

I am using IIS (v 6.0 and 5.1). At first I thought this was a system
resource access issue with the user account that IIS uses for this web
site, but after giving this user full access, Im still at a loss. Can
anyone shed some light on my delema? Thanks in advance.

Brandon
 
M

Matt Garrish

Ok I have an issue with a CGI script that I have written in Perl using
the Win::ODBC module for db access. I have a System DSN that I have
setup on the server and I want the script to use that ODBC DSN for
security reasons. The bit something like:

$DSN = "vrs";
if (!($db = new Win32::ODBC($DSN))){
print "Content-type: text/html\n\n";
print "Error connecting to $DSN\n";
print "Error: " . Win32::ODBC::Error() . "\n";
exit;
}

From all the examples I've seen, this work. However, when the script
is run I always get an error like: "the user '(null)' is not
associated with a trusted SQL server connection".

If I understand you correctly, it sounds like you haven't specified the
username and password for the DSN properly in the ODBC manager (i.e., there
is no default user and password for that DSN). Go to Settings -- Control
Panel -- Admin Tools -- ODBC Settings (or something similar depending on
your version of Windows) and trying testing the connection. If you can't
connect, then go over the settings and see what you've missed. Also, make
sure that you've set it up as a System DSN and not a User DSN.

It definitely doesn't sound like a Perl problem, though. I would personally
recommend you switch to the DBI and DBD::ODBC modules, however, as support
for Win32::ODBC is suspect.

Matt
 
B

brandony

Matt said:
If I understand you correctly, it sounds like you haven't specified the
username and password for the DSN properly in the ODBC manager (i.e., there
is no default user and password for that DSN). Go to Settings -- Control
Panel -- Admin Tools -- ODBC Settings (or something similar depending on
your version of Windows) and trying testing the connection. If you can't
connect, then go over the settings and see what you've missed. Also, make
sure that you've set it up as a System DSN and not a User DSN.

It definitely doesn't sound like a Perl problem, though. I would personally
recommend you switch to the DBI and DBD::ODBC modules, however, as support
for Win32::ODBC is suspect.

Matt

Matt,
I don't think its a problem with the ODBC connection. It is a System
DSN and I always get the green light when testing the connnection at
the end of setup. Any other ideas? I will look at the DBD::ODBC
modules. BTW, I agree that this doesnt seem like a perl problem, but
rather a setup issue with respect to the web site context (user rights
is was my first inclination). I just thought someone here may have had
similar issues.
 
B

brandony

Matt said:
If I understand you correctly, it sounds like you haven't specified the
username and password for the DSN properly in the ODBC manager (i.e., there
is no default user and password for that DSN). Go to Settings -- Control
Panel -- Admin Tools -- ODBC Settings (or something similar depending on
your version of Windows) and trying testing the connection. If you can't
connect, then go over the settings and see what you've missed. Also, make
sure that you've set it up as a System DSN and not a User DSN.

It definitely doesn't sound like a Perl problem, though. I would personally
recommend you switch to the DBI and DBD::ODBC modules, however, as support
for Win32::ODBC is suspect.

Matt

Matt,
I don't think its a problem with the ODBC connection. It is a System
DSN and I always get the green light when testing the connnection at
the end of setup. Any other ideas? I will look at the DBD::ODBC
modules. BTW, I agree that this doesnt seem like a perl problem, but
rather a setup issue with respect to the web site context (user rights
is was my first inclination). I just thought someone here may have had
similar issues.
 
M

Matt Garrish

brandony said:
I don't think its a problem with the ODBC connection. It is a System
DSN and I always get the green light when testing the connnection at
the end of setup. Any other ideas? I will look at the DBD::ODBC
modules. BTW, I agree that this doesnt seem like a perl problem, but
rather a setup issue with respect to the web site context (user rights
is was my first inclination). I just thought someone here may have had
similar issues.

A lot depends on what type of database you're trying to connect to. MySQL
allows you to store the username and password for the DSN, but others like
MS SQL require login information to be supplied when you establish the
connection. The only thing I can suggest is that you try a newsgroup that
deals with your particular database. The problem itself is language agnostic
and ODBC specific, as you'd run into the same problem connecting to the
database regardless of which language you're using (which is why you're
getting a system error and not a perl error).

Matt
 
B

brandony

Matt said:
A lot depends on what type of database you're trying to connect to. MySQL
allows you to store the username and password for the DSN, but others like
MS SQL require login information to be supplied when you establish the
connection. The only thing I can suggest is that you try a newsgroup that
deals with your particular database. The problem itself is language agnostic
and ODBC specific, as you'd run into the same problem connecting to the
database regardless of which language you're using (which is why you're
getting a system error and not a perl error).

Matt

Matt,
Well ok, I am using MS SQL. So, I must provide my login credentials in
the perl script in this case? Are you sure? Because that sucks if
true. Can you direct me to any specific resource dealing with this
issue.

Thanks again for your feedback.
 
M

Matt Garrish

brandony said:
Well ok, I am using MS SQL. So, I must provide my login credentials in
the perl script in this case? Are you sure? Because that sucks if
true. Can you direct me to any specific resource dealing with this
issue.

Don't quote me on MS SQL. I only access one MS SQL database, and it's not
for the web. You may be able to configure access to the database for the
iusr account in MS SQL (and by switching the login option in the ODBC
manager to Windows NT Authentication), but having never done so I can't
really be of any further assistance to you.

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top