Actually, you don't even need to set up the DSN ahead of time.  Something 
like this will make the connection to an MS Access file on a Windows platform.

         use DBI;
         require DBD::ODBC;
         my $source_file = "i:\\Data\\Hanford\\Databases\\Hanford.mdb";
         my $con_str = "dbi:ODBC:driver=Microsoft Access Driver (*.mdb);"
                                         . "dbq=$source_file";
         my $dbh=DBI->connect($con_str, '', '')
                                         or die "Error 
connecting:  $DBI::errstr\n";

 From which point $dbh will work like the usual DBI database handle.

Morag

At 06:49 PM 3/19/01 -0600, Steve Howard wrote:
>I actually use dbd::odbc quite often to access an Access database (Although
>I am usually migrating something OFF of the Access database rather than
>using Access). It's not really any trick. You need to set up a DSN in your
>ODBC Data Sources. That is very easy if you are on an MS platform (Just In
>Case - It's in your control panel). If you are on a Linux platform, you can
>get the iODBC drivers to access an Access database.
>
>Once you get the DSN configured, and pointing to the Access database you
>wish to access, all there is to it code wise is something like this:
>
>   use DBI;
>   my $dsn               = "dsn_name";
>   my $database          = "DBI:ODBC:$dsn";
>   my $db_user           = "";
>   my $db_password       = "";
>
>   # connect to the Access db.
>   my $dbh = DBI->connect($database,$db_user,$db_password);
>
>You should be there.
>
>
>Steve Howard
>
>-----Original Message-----
>From: Michael A. Chase [mailto:[EMAIL PROTECTED]]
>Sent: Monday, March 19, 2001 2:06 PM
>To: Alex; [EMAIL PROTECTED]
>Subject: Re: MS Access
>
>
>Microsoft provides ODBC drivers for Access.  That should mean you can use
>DBD::ODBC with DBI to work with Access.  Exactly how useful this is for you
>depends on you platform.
>
>Without knowing what you have already tried, and what problems you had, it
>will be difficult for anyone on the list to make any suggestions.
>
>--
>Mac :})
>** I normally forward private database questions to the DBI mail lists. **
>Give a hobbit a fish and he'll eat fish for a day.
>Give a hobbit a ring and he'll eat fish for an age.
>----- Original Message -----
>From: "Alex" <[EMAIL PROTECTED]>
>To: <[EMAIL PROTECTED]>
>Sent: Monday, March 19, 2001 11:31 AM
>Subject: MS Access
>
>
> > Sorry to bother you but I feel pretty dumb by searching the net and
> > reading page after page without understanding anything. I use perl and
> > mysql alot and I would like to access a microsoft Acess MDB file just
> > like I access a mysql database.
> >
> > What would I have to do? I just don't get it. Every driver I installed
> > just gives me new hints an trying other installs and so on. Is there any
> > page that explains actually what to do? I can't be the first person with
> > this problem.


Morag K. Smith
NIS-5 Safeguards Science and Technology
Mail Stop E540
Los Alamos National Laboratory
Los Alamos, NM 87545
Voice:  (505) 667-3080
FAX:  (505) 665-4433

Reply via email to