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

0
angel
11/13/2002 11:04:25 PM
perl.beginners 29388 articles. 4 followers. Follow

4 Replies
1396 Views

Similar Articles

[PageSpeed] 48

Hi -

I have never heard of the "Sql" method in DBI. Something like this works:

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: 'beginners@perl.org'
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: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org



0
beau
11/14/2002 12:55:50 AM
> Hi,
>=20
> I am trying to write a script that copies an information from=20
> ACCESS but
> it gives me the following error:
>=20
> Can't call method "Sql" on an undefined value at=20
> franowner.pl.txt line 4.
>=20
> Here's the script:
>=20
>=20
> use Win32::ODBC;
> $DSN=3D"db1";
> $db =3D new Win32::ODBC("db1");

you should check if $db is defined, otherwise there has been an error

die "Error: " . Win32::OLE->LastError if  !$db;


> $db->Sql("SELECT owner_first_name, owner_last_name FROM Owners WHERE
> ID=3D11");
> if ($db->Error()) {
> print "Error: $db->Error";
> }
> statement:\n$DBI:errstr\n";
> ($ownerfname,$ownerlname) =3D $db->FetchRow();
> print "Database results: first name $ownerfname and last name
> $ownerlname\n";
> $db->finish;
> $db->disconnect || die "Cannot disconnect from database";
>=20
> Please, help me with this problem.
> ____________________________________________________
> =CA=E0=EA=E2=EE =E5 =F0=E5=EA=EB=E0=EC=E0 =E2 =
=C8=ED=F2=E5=F0=ED=E5=F2? - http://reklama.mail.bg
>=20
>=20
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
>=20
>=20
>=20
>=20
> --=20
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
>=20
0
toby
11/14/2002 1:10:32 AM
----- Original Message -----
From: "Beau E. Cox" <beau@beaucox.com>
To: "Angel Iliev Kafazov" <angel.kafazov@mail.bg>; <beginners@perl.org>
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: 'beginners@perl.org'
> 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: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
>
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
>

0
dgardiner
11/14/2002 6:31:41 AM
Thank you for correcting me Douglas - I have worked
exclusively with DBI. It's good to learn something new!

Aloha => Beau.

-----Original Message-----
From: Douglas Gardiner [mailto:dgardiner@houston.rr.com]
.....
> 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
.....


0
beau
11/14/2002 10:10:03 AM
Reply:

Similar Artilces:

accessing access
------=_NextPart_000_029B_01C29063.1E2098D0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi! I am trying to access an access mdb file for the first time. I get the following error: Can't connect(dbi::ODBC:pfawtbls.mdb ), no database driver specified and DBI_DSN env var not set at jfa_data.pl line 147 for the code: my $dbh = DBI->connect( "dbi::ODBC:pfawtbls.mdb", "", "", ) or die "Unable to connect: ". $DBI::errstr. "<br>"; What am I missing? Thanks, Jer...

Access access
========== Hi, Everyone ... I'm going to lock this thread for now. If you have a question about working with Access in Web Matrix, please start a new thread in this forum. Otherwise, this thread will get to be unwieldy. Thanks! ========== Updated 6/29/03 Hello, everyone. I've been working with the new version of Web Matrix (version .6, build 812, available right now!). In particular, I've been playing with support for Microsoft Access, which is one of the great new features in the new release. I wrote up some notes on what I've found to share some of my experiences and to a...

How to access remote Access database?
Hello everyone, What are the permissions we have to give in the Acess db which is in remote? It would be really great if you share me some ideas. Have a good one. Thanks!!!    http://databases.aspfaq.com/database/why-can-t-i-access-a-database-or-text-file-on-another-server.htmlhttp://forums.asp.net/t/1381295.aspx...

Exception accessing Access database
Hi, I am trying to connect to access database. dim objcon as new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\ASPNET\banking.mdb") dim objcmd as new OleDbDataAdapter("select * from Names", objcon) dim ds as DataSet = new DataSet() objcmd.Fill(ds,"Names") MyDataList.DataSource = ds.Tables("Names").DefaultView MyDataList.DataBind() The above is the piece of code where i am getting error The error is Source Error: Line 10: dim ds as DataSet = new DataSet() Line 11: ...

Centrailized access for access database
i want to convert a vb application into asp.net  and back end as access database.how to get an centrailzed access using access database and thru web forms.any help.  Jai Ganesh. J , GSD ,IndiaPlease Mark As Answer If my reply helped you. any help would be more appericated Jai Ganesh. J , GSD ,IndiaPlease Mark As Answer If my reply helped you. could not found any reply Jai Ganesh. J , GSD ,IndiaPlease Mark As Answer If my reply helped you.  Any possible solutions would be more appreciated Jai Ganesh. J , GSD ,IndiaPlease Mark As Answer If my reply help...

Accessing a MS Access database
Hi, I would like to do a lookup into an Access database, and display the result in a grid. I'm an embedded programmer being thrown into the world of .net, asp, VB, and databases so I don't know where to start :-) ...... can anyone help me ? Thanks. Really jus ta matter of making a connection, doing your query, and displaying results. Here is a sample from a module I use. The data is bound to a datagrid. Sub LoadSchedule() Dim strSrc As String = CType(Settings("src"), String) If Trim(strSrc) <> "" Then ...

Accessing an Access Database on Linux
------=_NextPart_000_000E_01C1DB0F.7665F3F0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit I need to access a MS Access Database residing on a Linux box and perform some queries. Any suggestions? Thanks in advance. ------=_NextPart_000_000E_01C1DB0F.7665F3F0-- ...

Problems accessing access database
Running netware 6.1 with SP1A. When several users access the access database the second user tries to open you will receive a message that says there is a table that is exclusivly open by another user, so we can not open the document. How to make it work with databases. Is it possible that you are using an 4.90SP1 client? If yes, you should use 4.90SP1a instead -- Marcel (using XanaNews 1.16.1.6) I can resist everything but temptation >Running netware 6.1 with SP1A. Actually 6.5 I suspect. -- Andrew C Taubman Novell Support Forums Volunteer SysOp http://sup...

Problem in accessing access database
Hi  I am establishing connection with MS access. MS Access Database is placed in the same directory as the project.Connection string is " "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=testdb.mdb"   But I am getting the error  the file "testdb.mdb" not found   Can anyone please tell me what is wrong with the connection string Regards KaranRegardsKaran GuptaFor .net,Javascript and Sql server articles and interview question visithttp://guptakaran21.googlepages.com/main Try putting the DB in the APP_Data folder or changing 'testdb.mdb&#...

accessing remote access database
Hi to all, When ever i need to add or delete something from the mdb file where I cant do it in my web site, i am downloading the mdb file, doing the modifications then uploading again.I want my code running on localhost to reach the mdb file on my web site and do any modifications. I have tried to replace the following code string path = Request.MapPath(@"mydb.mdb") with string path = Request.MapPath(@"http://www.mysite.com/mydb.mdb") but i get the error "A virtual path is expected. " Is there a way to reach a remotely hosted mdb file ?   Thanks in advance short answer : No,...

Accessing a Microsoft Access Database
Hello all, I'm relatively new to the list, so I'm sorry if I'm going over old ground here ! I would like to use PERL to view information in a Microsoft Access Database and then use this information in other programs away from the Database. Trouble is, I'm slightly confused by all the information on offer and am not sure=20 of the best way to proceed to allow PERL to gain the information in the Database and I'm also unsure exactly what I need to install on the machine. Does anybody know of a useful web site that I can look at or does anybody have any simpl...

Accessing single column from Access Database
Hehe, total newbie question here but say if i wanted to access only one row from a database and store the columns in separate variables how would i go about doing this?  Preferably in c#. The reason that im asking is that im makin a custom login control reading uername and password from a database and want to compare them with user input values I have no problems using the repeater and datagrid etc.  Thanks! Drew  Hello Drew, Good place to start is: http://asp.net/learn/data-access/ Especially tutorial #1. Jeroen Molenaar.--------------------------------Jer...

Accessing an Access database from a Unix box
Hello All, I am currently NOW trying to access an Access database filename.mdb from a shared drive on my Unix box. Now all I want to do is extract data from an SQL query from this database? Can this be done? I don't think I will need to use Win32::ODBC but instead something else like DBD::odbc? Is this correct? Kind regards, Dan ...

How to get an access to MS Access database?
Is it possible to get normal access to MS Access database without OLE DB drivers just with methods of ASP.NET. The problem is that the hoster set trust level to medium and does not allow using of OLE DB drivers. Thank you....

Web resources about - accessing ACCESS database - perl.beginners

Highest Percentage Of Opera Mini Users Accessing Facebook? Macau
If you were asked to guess which country had the highest percentage of users of Opera mobile Web browser Opera Mini users accessing Facebook ...

International Users Accessing Facebook Places Through US VPN Accounts
By using a virtual private network (VPN) hosted in the United States, Facebook users from around the world are accessing Facebook Places. The ...

What are some alternatives to Yodlee for accessing bank information?
Clay Loveless , Founder, Jexy. Co-founder, Mashery. Founder, Jexy. Co-founder, Mashery.

Cloud Console - Accessing files in cloud storage for iPad on the iTunes App Store
Get Cloud Console - Accessing files in cloud storage on the App Store. See screenshots and ratings, and read customer reviews.

Meryl Streep On Accessing The Characters Within - YouTube
Meryl Streep talks about the importance of an actors work representing their ability. CONNECT WITH AFI: http://facebook.com/AmericanFilmInstitute ...

Student pleads guilty to accessing records about Frances Abbott design scholarship
The Sydney student who leaked information about a fashion school scholarship controversially awarded to the daughter of the Prime Minister has ...

Accessing a headline opinion
Accessing a headline opinion

Sharp increase in authorities accessing private data
Australian law enforcement and government agencies have sharply increased their access without warrant to vast quantities of private telephone ...

Former librarian charged with accessing student records of Frances Abbott
A former part-time librarian at a Sydney design school has been charged after she allegedly accessed student records of Prime Minister Tony Abbott's ...

Frances Abbott scholarship: Sydney woman pleads guilty to accessing Whitehouse Institute records on PM's ...
A Sydney woman who leaked the student records of Tony Abbott's daughter pleads guilty. A Sydney woman who leaked the student records of Prime ...

Resources last updated: 12/26/2015 7:23:08 AM