programming-examples/perl/Win32/Creating a Data Source Name (DSN).pl
2019-11-15 12:59:38 +01:00

34 lines
968 B
Perl

use Cwd;
use Win32::ODBC;
$DriverType = "Microsoft Access Driver (*.mdb)";
$DSN = "Email Contacts";
$Description = "Description=Email List and Contact Information";
$DataBase = "EmailContacts.mdb";
$dir = cwd();
if (Win32::ODBC::ConfigDSN(ODBC_ADD_DSN,
$DriverType,
("DSN=$DSN",
$Description,
"DBQ=$dir\\$DataBase",
"DEFAULTDIR=$dir",
"UID=", "PWD="))){
print "Successful configuration of $DSN!\n";
}
else{
print "Error Creating $DSN\n";
Win32::ODBC::DumpError();
die;
}
my $myDb = Win32::ODBC->new($DSN);
my $connection;
if (! $myDb){
print "Failed to Connect $DSN\n";
Win32::ODBC::DumpError();
die;
}else {
$connection = $myDb->Connection();
print "Successful Connection $connection, $DSN\n";
}
$myDb->Close();