你的分享就是我们的动力 ---﹥

Perl 创建一个新的 ODBC 数据源

时间:2013-05-30 00:08来源:www.chengxuyuans.com 点击:

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();

转载注明地址:http://www.chengxuyuans.com/Perl/63099.html