DCSIMG
SQL select on several different tables that are in different databases and on different servers that are not in the same subnet mask - Natalie Reznik

Natalie Reznik

"It's not a bug, it's a feature !" Unknown Programmer

SQL select on several different tables that are in different databases and on different servers that are not in the same subnet mask

Recently I needed to run a select on 5 different tables that sat on different servers spread all over the internet. At a certain point i almost gave up, as i thought it can't be done. But i believed in the abilities of MS SQLServer 2005 that helped me out so many times and kept searching and trying all sorts of tricks. Here's the final result:

1. When you want to connect from one server to another you need to make sure that the Sql Server Agent is with a green arrow on the server you connect to:

2. go to the server objects  --->  linked servers add new linked server .

When you add a new linked server you add it by its name (and not by IP), which would be just fine if those servers are in the same subnet mask. But in my case they were not, and because of that they couldn't find each other.

3. to overcome this problem you need to "tell" the system where to look for that server and that you do in the file named "hosts" that can be found at:

C:\WINDOWS\system32\drivers\etc

this a text file and all you need to do is add at the bottom of this file "registration" for your server like this:

123.45.6.789  MyServer

where 123.45.6.789 is the IP of the server and "MyServer" is its name.
after that servers start to find each other even by name.

I suppose that this is a pretty trivial thing for someone who knows SQLServer well , but for me and my friends it was something new, so i hope it will help someone.

And off course a lot of credit goes to my genius boyfriend Adlai Mashiach whom many of you know and love. Without his help i wouldn't solve this. Don't forget to come to his lecture on LINQ the day after tomorrow. I've seen the lecture - it's really good!

Comments

Adlai Maschiach said:

BTW this trick is also true for SQLServer 2000

# February 4, 2008 2:25 PM

Adlai Maschiach said:

Another thing , in order to know this trick you have to connect your knowledge in SQL Server ( linked server ) and with knowledge in System ( etc/host ) - So NO this is not that trivial , not everybody knows them both , or succeed in connecting the dots  between the two

And natasha YOUR ARE THE GENIUS in the family =)

# February 4, 2008 2:32 PM

Ella Maschiach said:

אהבתי, תודה על הטיפ :)

# February 5, 2008 10:05 AM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: