在PERL中从Windows访问Microsoft SQL Server [英] Accessing Microsoft SQL Server from Windows in PERL

查看:48
本文介绍了在PERL中从Windows访问Microsoft SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SQL Server驱动程序.但这是我得到的以下错误:

I am using SQL Server driver. But this is the following error I get:

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,而不包含其内容.

Note that '' string does not interpolate your variables, so in your example $dsn string contains verbatim $database or $host, not their contents.

这篇关于在PERL中从Windows访问Microsoft SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆