Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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,
Jasmine


Comment on Setting up MS Access as an ODBC Data Source
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://142481]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2014-12-22 12:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (116 votes), past polls