gpt4 book ai didi

sql-server - 在 PERL 中从 Windows 访问 Microsoft SQL Server

转载 作者:行者123 更新时间:2023-12-01 11:04:48 25 4
gpt4 key购买 nike

我正在使用 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 $host,而不是它们的内容。

关于sql-server - 在 PERL 中从 Windows 访问 Microsoft SQL Server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6983586/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com