You can create a text file with the following information on the fly and output it to a filename and directory of your choice.  I give mine a *.dsn extension.  Notice DefaultDir= and DBQ= should point to the directory and filename you output the DSN info to.

 

[ODBC]

DRIVER=Microsoft Access Driver (*.mdb)

UID=admin

UserCommitSync=Yes

Threads=3

SafeTransactions=0

PageTimeout=5

MaxScanRows=8

MaxBufferSize=512

FIL=MS Access

DriverId=281

DefaultDir='\\server\directorypath'

DBQ='\\server\directorypath\databasename.mdb'

 

 

 

Then in your program include this use clause at the top:

 

use Win32::ODBC;

 

 

Then later in your program add a couple subroutines that

You can call to open and close the database.

 

sub Open_Database() {

   my $FILEDSN="FILEDSN=\\\\server\\directorypath\\databasename.dsn";

   $db = new Win32::ODBC($FILEDSN);

   if (! $db) {

     my $error=Win32::ODBC::Error();

     Win32::GUI::MessageBox($WindowName,

         "Can't Establish Database Connection using:\n$FILEDSN\n$error",

         "Application Name - Error",16,);

     return 1;   

   }

   return 0;

}

 

sub Close_Database() {

   $db->Close();  # close the database connection

   undef $db;

}