Thank you very much for the support. I tried whatever you recommended me and I isolated the error in the sql statement. The script connects to the database and returns defined $db var but after this it cannot execute the sql. I double-checked my table and columns, though I still have no idea why it is not working:(
the script: use Win32::ODBC; $DSN="db1"; my($db) = new Win32::ODBC("db1") || die "Cannot open connection to database"; die "Error: " . Win32::OLE->LastError if !$db; $db->Sql("SELECT owner_first_name, owner_last_name FROM Owners WHERE ID=11") || die "Cannot execute sql statement"; if ($db->Error()) { print "Error: $db->Error"; } ($ownerfname,$ownerlname) = $db->FetchRow(); print "Database results: first name $ownerfname and last name $ownerlname\n"; $db->finish; $db->disconnect || die "Cannot disconnect from database"; Douglas Gardiner <[EMAIL PROTECTED]>: > > ----- Original Message ----- > From: "Beau E. Cox" <[EMAIL PROTECTED]> > To: "Angel Iliev Kafazov" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> > Sent: Wednesday, November 13, 2002 6:55 PM > Subject: RE: accessing ACCESS database > > > > Hi - > > > > I have never heard of the "Sql" method in DBI. Something like this > works: > > > That's because he's using a different module and not the DBI module. > It's > Win32:ODBC > > From what I remember, been a long time. Unless you check that the > object > was called correctedly at the beginning, you will get that error. Few > things to check are: > > make sure DSN is setup and the name is the same. > make sure you have the module installed > the ever so popular constant error checking to make sure not only that > it > connects but also a graceful exit upon error or some kind of error > trapping > in case the SQL statements or anything else fail. > > Alos with this setup the datbase must be on that machine otherwise you > need > to use the proxy module for connection. Either way, the initial call > must > be checked when using Win32:ODBC to make sure it connects. It doesn't > complain until you make another call otherwise. > > something like: > > $db = new Win32::ODBC("db1") || die "cannot open database"; > > at least you will know if it connects. There are other methods to use, > but > I do not remember since I personally use DBI so much. > > > use strict; > > use warnings; > > use DBI; > > > > my $dbh = DBI->connect("DBI:ODBC:cpan") > > || die "could not connect to ODBC:MyDatabase:\n$DBI::errstr\n"; > > > > my $stmt = "select * from modules;"; > > > > my $sth = $dbh->prepare($stmt); > > $sth || > > die "could not prepare ($stmt):\n$DBI::errstr\n"; > > > > my $rv = $sth->execute > > || die "could not execute ($stmt):\n$DBI::errstr\n"; > > > > while (my $row_ref = $sth->fetchrow_arrayref) { > > print "$_\t" for (@ { $row_ref } ); > > print "\n"; > > } > > > > $sth->finish; > > $dbh->disconnect > > || die "could not disconnect to ODBC:MyDatabase:\n$DBI::errstr\n"; > > > > Check out DBI.html in your /perl_install_dir/html/site/lib (jf you > are > > using ActivePerl). > > > > Aloha => Beau. > > > > -----Original Message----- > > From: Angel Iliev Kafazov [mailto:angel.kafazov@;mail.bg] > > Sent: Wednesday, November 13, 2002 1:04 PM > > To: '[EMAIL PROTECTED]' > > Subject: accessing ACCESS database > > > > > > Hi, > > > > I am trying to write a script that copies an information from ACCESS > but > > it gives me the following error: > > > > Can't call method "Sql" on an undefined value at franowner.pl.txt line > 4. > > > > Here's the script: > > > > > > use Win32::ODBC; > > $DSN="db1"; > > $db = new Win32::ODBC("db1"); > > $db->Sql("SELECT owner_first_name, owner_last_name FROM Owners WHERE > > ID=11"); > > if ($db->Error()) { > > print "Error: $db->Error"; > > } > > statement:\n$DBI:errstr\n"; > > ($ownerfname,$ownerlname) = $db->FetchRow(); > > print "Database results: first name $ownerfname and last name > > $ownerlname\n"; > > $db->finish; > > $db->disconnect || die "Cannot disconnect from database"; > > > > Please, help me with this problem. > > ____________________________________________________ > > Какво е реклама в Интернет? - http://reklama.mail.bg > > > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > -- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > ____________________________________________________ Какво е реклама в Интернет? - http://reklama.mail.bg -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]