我正在使用 SQL Server 驱动程序。但这是我得到的以下错误:
DBI connect('Driver={SQL Server}:$database:$host','cartertest',...) failed:
[Microsoft][ODBC Driver Manager] Invalid connection string attribute (SQL-01S00)
at PERL_SQL_Connect.pl line 15
Can't call method "disconnect" on an undefined value at PERL_SQL_Connect.pl line 16
这是我的代码:
use DBI;
use DBD::ODBC;
#my $dsn = "dbi:SQL Server:$database:$host";
my $dsn = 'DBI:ODBC:Driver={SQL Server}:$database:$host';
my $host = 'amber'; ##This is the server name
my $database = 'assignmentdb'; ##This is the database name
my $user = 'something'; ## Database User Name
my $auth = "something";
#my $dsn = "dbi:SQL Server:$database:$host";
$dbiconnect = DBI->connect($dsn,$user,$auth); #line 15
$dbiconnect->disconnect(); #line 16
我犯了什么错误?
你可以试试这个:
use DBI;
my $host = 'amber';
my $database = 'assignmentdb';
my $user = 'something';
my $auth = 'something';
my $dsn = "dbi:ODBC:Driver={SQL Server};Server=$host;Database=$database";
my $dbh = DBI->connect($dsn, $user, $auth, { RaiseError => 1 });
# .... work with the handle
$dbh->disconnect;
注意''
字符串不会插入你的变量,所以在你的例子中$dsn
字符串包含逐字内容$database
or $host
,而不是它们的内容。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)