How do I use Win32::SqlServer to connect remotely?
I have been unable to make a successful connection to my SQL Server (2005) using Win32::SqlServer. The server is located on another machine. I am using the latest version of ActivePerl and th开发者_StackOverflowe module.
Using an ADO.NET provider (in C#), I can make a successful connection with the connection string:
Data Source=1.2.3.4,1553;Initial Catalog=dbname;User Id=username;Password=pw;
In an effort to convert this in to Perl, I've attempted the following:
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();
As well, I've attempted to set the server, login information, and initial database individually using setloginproperty().
These all fail with the message after the timeout period has been met:
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
The reason the early example was failing is because the sql_init()
method expects arguments passed in to it.
In order to use the setloginproperty()
to inject settings, ->new()
should be used to create an uninitialized SqlServer object!
精彩评论