2009-11-02 104 views
0

我一直无法使用Win32 :: SqlServer成功连接到我的SQL Server(2005)。服务器位于另一台机器上。我正在使用最新版本的ActivePerl和模块。如何使用Win32 :: SqlServer远程连接?

使用(在C#)的ADO.NET提供,我可以在连接字符串连接成功: Data Source=1.2.3.4,1553;Initial Catalog=dbname;User Id=username;Password=pw;

在努力将此转换到Perl中,我已经尝试以下:

my $conn = Win32::SqlServer::sql_init(); 

$conn->setloginproperty('ConnectionString', 'Data Source=1.2.3.4,1553;Initial Catalog=dbname;User Id=username;Password=pw;'); 
print $conn->connect(); 

同时,我已经尝试设置服务器,登录信息,以及初始数据库单独使用setloginproperty()。

这些都失败消息的超时时间已经达到后:

SQL Server message 2, Severity 16, State 1 
Named Pipes Provider: Could not open a connection to SQL Server [2]. 
Message 08001 from 'Microsoft SQL Native Client', Severity: 16 
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. 
Message HYT00 from 'Microsoft SQL Native Client', Severity: 16 
Login timeout expired 
Terminating on fatal error at mkadm.pl line 54 

回答

0

早期的例子是失败的原因是因为sql_init()方法预计将它传递的参数。 为了使用setloginproperty()来注入设置,应该使用->new()来创建未初始化的SqlServer对象!