我想让我的Perl脚本使用ODBC连接字符串连接到数据库。这适用于下面的代码。但我也希望它使用我已经输入到ODBC连接的用户名和密码。我不想在脚本中提供这些内容。Perl没有密码的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必须设置密码(消隐pwd不是选项)。
操作系统是Windows 2008 R2(64位)。 ODBC连接在系统DSN中定义为32位。 Perl版本是32位。连接已完成到MSSQL 2008 R2。
你连接了哪个数据库? –
该数据库是MSSQL 2008 –