Connecting to MS-SQL server in Linux via Perl
-
I posted this over at PerlMonks and someone suggested posting it here.
So here is the post:
Hello, I am currently trying to connect to a MS-SQL server in Linux. I have using the Sybase method to connect, but recently ran into an issue with a different server.
All of the previous servers have been straightforward, but this one has a slash in the name of the server. It is called ORCXPDB1C2\SQL. I add an additional slash in the server definition, but I am still having troubles connecting.Here is the connection information:
use DBI;
my $user = "xyz";
my $passwd = "xyx2";
my $server = "ORCXPDB1C2\SQL";
my $dbh = DBI->connect("DBI:Sybase:server=$server", $user, $passwd, {PrintError => 0});
If I connect to MS SQL servers without the slash, I can connect just
fine with the above method. Not sure how to get around this issue.Thank you!
-
What is the error message being returned?
-
It is just getting to my die message since it is unable to connect. I am trying to see if there are other methods to connect with \ in the server name. So far, I am not having much luck.
-
Figured it out - change the connection string. Remove the server distinction and put the full hostname and the port number. I was able to connect and get my script to work properly.
-
unixODBC works well too, and lets you write to a more generic interface.
-
Does linux have a HOSTS file that lets you assign (mostly) arbitrary names to IP addresses?
If so, you might consider removing the hard-coded IP address from the code and using a HOSTS entry.
-
@RaspenJho said:
Does linux have a HOSTS file that lets you assign (mostly) arbitrary names to IP addresses?
The Windows HOSTS file is named for /etc/hosts on unix systems. Modern linux platforms can do far more than just that.
If so, you might consider removing the hard-coded IP address from the code and using a HOSTS entry.
Or you could use a config file, or a DNS server, either of which is usually more sane.
-
just a wild guess:
my $server = "ORCXPDB1C2\\SQL";
my $dbh = DBI->connect("DBI:Sybase:server=$server", $user, $passwd, {PrintError => 0});Maybe the "DBI:Sybase:server=$server" becomes "DBI:Sybase:server=ORCXPDB1C2\SQL"
On which the \S is an escape sequence? Try "ORCXPDB1C2\\\\SQL" as server string?
(no perl experiance here :P just guessing)