Click to See Complete Forum and Search --> : Problem with ODBC connection in Perl


Simonliu
07-08-2003, 10:10 PM
Hi ppl,

I have a really annoying problem with this Perl script of mine, where it accepts user input and updates a MS Access 2000 database with it, through an ODBC connection made by using the Win32::ODBC library. The problem is that the connection keeps on failing, but there is no error message that appears!

The main bit of problematic code is:

$query = "INSERT INTO MAIN (category, subcategory, url, user) VALUES ($fields{'SelectPrimary'},
$fields{'SelectSecondary'}, $fields{'url'}, $fields{'name'})";

$conn = new Win32::ODBC("website");

if (!$conn) {
die "ODBC DSN error: [$!].\n";

}

Where the script dies on the "if" statement, but no error messages are produced since there is nothing displayed in the square brackets. So what is going on? Also, could it be a problem with the webserver that I am running? Its IIS 5.0, and i'm not sure how to configure it (I only stuff about Apache).

I'll be glad to send anyone who requests it, the source code of the script.

Any help with this problem will be greatly appreciated,

Simon Liu

Jeff Mott
07-09-2003, 02:14 AM
Perl's built-in functions set $! when an error is encountered, but modules are under no obligation to do the same. You will have to read the documentation to see how each library provides access to errors.

http://search.cpan.org/author/GSAR/libwin32-0.191/ODBC/ODBC.pm

In this case Win32::ODBC has an Error() method that returns the last encountered error.

Simonliu
07-09-2003, 06:56 AM
I have previously already done that, using:
my($err) = $conn->Error();
print "$err";
Before using the code that I have outlined above, but in that case another error was generated, where it said that the method "Error()" doesn't exist. That's why I used that construct, because it gave no errors. I'm guessing that there could be a problem with connecting to the ODBC DSN, but another little script I wrote, which justs connects and prints out the database, works and I haven't changed anything.

Simon