0

I have a program in excel that connects to several sql servers using servername and instance. My question is, what would happen if there are two servers (machines) with the same servername in the same network? Is that posible?

How can this be prevented?

Is it saver to connect with IP rather than with servername?

5
  • 1
    are you talking about the hostname of the machine? if you are, the answer is no.
    – DanBig
    Sep 13, 2013 at 16:36
  • @DanBig I am talking about the servername that appears on the connection properties on SQL Server Management Studio. Is this the same hostname?
    – ia.solano
    Sep 13, 2013 at 16:40
  • running a select @@servername in most cases, should return the same value as the actual host name of the machine. In the case of replication, it will not work if they dont match.
    – DanBig
    Sep 13, 2013 at 16:44
  • If you're talking about the Instance Name, you need to say Instance Name because you're just confusing the point. I am 95% certain that this is what you're talking about, and no it doesn't matter.
    – Sammitch
    Sep 13, 2013 at 16:56
  • 1
    You're posing a hypothetical question and as such this isn't related to a "real" problem that you're having. Can two Windows computers in the same network have the same name? Yes and no. If the computers are domain joined the answer is no. If they aren't domain joined then the answer is yes, but problems would ensue. Can two different SQL Server instances on two different computers have the same instance name? Yes and no. They could have the same instance name but since a connection to an instance needs both the server name and the instance name it's unlikely this would cause any problems.
    – joeqwerty
    Sep 13, 2013 at 17:13

2 Answers 2

2

In very special circumstances, you have have multiple servers that respond to the same name. However, each server still has its own name that can not be shared.

If you attempted to set both to have the same name then either you would randomly get connected to one server or the other, or one would just "take" the name for itself and the other would fail.

Generally connecting via IP is bad because IP's change more often than hostnames. That's the point of a hostname: to provide the ability to locate an IP by a meaningful name so that the IP can change as network needs dictate.

3
  • Then what is the "best" way to connect to a sql server in a machine?
    – ia.solano
    Sep 13, 2013 at 16:52
  • 1
    servername\instance, or servername if it's not a named instance. Sep 13, 2013 at 17:05
  • If you're simply asking "is IP safer than hostname", the answer is no, one is not inherently safer than the other. However, considering that a) generally two servers can not have the same name, and b) hostnames are more flexible, the best practice is usually to use hostnames.
    – longneck
    Sep 13, 2013 at 17:50
2

When two Windows computers are in the same domain, they plainly and simply can't have the same hostname. This is not allowed.

If instead they are in a workgroup, or in different domains, you could name them with the same name, but then they would start throwing errors as soon as they locate each other; however, if they are in different IP subnets, there are no ways for them to discover this, so they would happily keep using the same hostname.

Now, about all the other computers trying to reach them. Mapping a hostname to an IP address is done by DNS; thus, even if you had two servers with the same name, the one you actually connect to would be the one registered in the DNS, and the other one would simply be never used. Unless you have duplicate DNS entries; in this case, you'll have a 50% chance of connecting to each server.

Not the answer you're looking for? Browse other questions tagged .