DMan
DMan

Reputation: 429

DBI - MSSQL - Connection string with instance name

I have two MSSQL instances: SERVERNAME1 and SERVERNAME2\SQL01 to which I try to connect from Linux machine using DBI:Sybase.

I have no problems to connect to SERVERNAME1, I use:

DBI->connect("dbi:Sybase:server=SERVERNAME.domain.com:PORT;database=master", "user", "pass")

and this works fine for me. The second server contains instance name also (SQL01)... So, my question is - How should I build connection string for SERVERNAME2\SQL01 ? I need to pass also domain.com and PORT within it.

Many thanks for help.

Upvotes: 0

Views: 1250

Answers (2)

RustyShanklin
RustyShanklin

Reputation: 1

Each DB instance is mapped to a specific port on the server. As long as the DBA does change the mapping, you can either ask the DBA what port the database is served on or you can use this routine to find out what instance is mapped to what port. Just call the program with the IP address of the server. Edit your freetds.conf file based on the output of this program.

#!/usr/bin/perl
$|++;
use strict;
use IO::Socket::INET;
my $message = new IO::Socket::INET(Proto => "udp", PeerPort => 1434, PeerAddr => "$ARGV[0]", LocalPort => 1434,  Timeout => 10)
  or die "Can't make UDP socket: $@";
$message->send("\x02");
print "Sent message, waiting on response\n";
my ($datagram,$flags);
$message->recv($datagram,1024,$flags);
#print "Got message from ", $message->peerhost,", flags ",$flags || "none",": $datagram\n";
my @PARAMS=split(';',substr($datagram,3));
print "------------------\n Server $ARGV[0] reports:\n\n";
for(my $i=0;$i<($#PARAMS)+1;$i+=2) {
    if ($PARAMS[$i] eq "") {
       print "---------\n";
       $i--;
       next;
    };
    print "$PARAMS[$i]=$PARAMS[$i+1]\n";
};

-Rusty

Upvotes: 0

gbn
gbn

Reputation: 432180

Instance name is just a name for a port.
In some cases, you need to use port and not instance name

This is one such case.

A client makes a call to the SQL Server Browser on port 1434. This service resolves the port from the name. Not all clients know how to do this or may not be allowed too

The SQL Server names instance will need a static port assigned

Upvotes: 1

Related Questions