代码之家  ›  专栏  ›  技术社区  ›  Jesse Hallam

如何使用Win32::SqlServer进行远程连接?

  •  0
  • Jesse Hallam  · 技术社区  · 16 年前

    使用ADO.NET提供程序( 在C中# 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
    
    1 回复  |  直到 16 年前
        1
  •  0
  •   Jesse Hallam    16 年前

    早期示例失败的原因是 sql_init() 为了使用 setloginproperty() 要插入设置, ->new() 应用于创建未初始化的SqlServer对象!