【发布时间】:2011-09-06 14:09:13
【问题描述】:
我希望我的 Perl 脚本使用 ODBC 连接字符串连接到 DB。这适用于下面的代码。但我也希望它使用我在 ODBC 连接中输入的用户名+密码。我不想在脚本中提供这些。
有人知道如何实现吗?
use DBI;
my $strConn = "dbi:ODBC:MyDB";
my $username = "username";
my $password = "password";
# Does work
$dbh = DBI->connect( $strConn, $username, $password, { PrintError => 1, RaiseError => 1 } );
# Does not work
#$dbh = DBI->connect( $strConn, undef, undef, { PrintError => 1, RaiseError => 1 } );
if ($dbh)
{
print "OK\n";
} else {
print "FAIL\n";
}
注意:DB 必须设置密码(不能选择空白密码)。
操作系统为 Windows 2008 R2(64 位)。 ODBC 连接在 System DSN 中定义为 32 位。 Perl 版本是 32 位的。连接到 MSSQL 2008 R2。
【问题讨论】:
-
你连接的是什么数据库?
标签: database perl odbc connection-string