Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Setting up MS Access as an ODBC Data Source

by Jazz (Curate)
on Jan 31, 2002 at 18:52 UTC ( #142481=note: print w/replies, xml ) Need Help??

in reply to Opening files in MS Access

Yes, it is possible to open MSAccess files, as clemburg noted. You can also add, edit, delete, and query records in your MSAccess dbs from your Perl program.

Because MSAccess is an ODBC source, you can work with its files using Win32::ODBC in your program. Win32::ODBC is part of the libwin32 libraries in the Perl standard distribution.

Set up ODBC (if needed), then add the specific database as an the ODBC source.

To do this, go to your control panel and click "ODBC Data Sources". Under the User DSN tab, you should see something like "MS Access 2000 Database" and on the same line, "Microsoft Access Driver". If you do, you're good. If you don't, you'll need to install the additional ODBC drivers from your Win2k cd.

After you've confirmed that that the Access Driver is installed, click "Add" (in the User DSN window), select the Access Driver, then click Finish. Now you're at the setup window. Enter a mnemonic data source name, a short description, then click "Select" and browse to the Access db. If the db is password protected, click "Advanced" and enter the u/p.

At this point the db is registered as an ODBC source.

In your program, use Win32::ODBC and from there, it's straight SQL statements to insert, delete, query, etc.. Docs for Win32::ODBC are here. Here's some sample code:

use Win32::ODBC; my $db = Win32::ODBC->new('datasourcename'); # as defined in your ODBC + panel $db->Sql( "INSERT INTO tablename ( Field ) VALUES( 'text to insert' ) +); $db->Close();

Win32::ODBC is part of the libwin32 libraries, so if ActivePerl is installed, it ought to be installed correctly already. But you may want to install a more current version if available, which you can do by using the ppm manager (ppm.bat in your perl directory) and typing install libwin32 at the prompt.

Hope this helps,

Replies are listed 'Best First'.
Re: Setting up MS Access as an ODBC Data Source
by simon.proctor (Vicar) on Jan 31, 2002 at 23:13 UTC
    ODBC is definitely the way to go but if you do use ODBC then go for the DBI version rather than the Win32 version. This will make life easier when you change database vendors.

    I would also recommend avoiding Memo fields whereever possible. Othwerwise you are going to have to connect to the Access database using OLE.
Re: Setting up MS Access as an ODBC Data Source
by naive (Novice) on Feb 01, 2002 at 00:29 UTC
    Hi thks for all your reply.
    What I meant is that I have sorted some data and created a common separated file using perl.After which I want to open this particular file in MS Access through perl.
    I do not mean going into MS Access to delete/edit/add/query data that was already saved in MS Access.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://142481]
[stevieb]: choroba my GPS home device is done, at least prototype v1 is. I'm just making sure all of my code does what it says now
[stevieb]: I test/prototype code on my Pi, then I migrate it over to Arduino when it's ready (if that's a better platform for what I'm doing). The whole RPi stuff was for learning at first, then it snowballed. I'm just trying to get my in-house CI...
[stevieb]: ...done, which obviously requires a specific hardware setup.
[stevieb]: I don't write tests for the lower-level distributions (ie. ICs, sensors etc) within those distributions, I have all tests in a master distribution which encompasess all of the sub-modules

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2017-06-25 22:54 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (572 votes). Check out past polls.