-1

If we have multiple sql server instances in a computer, how can we know which one is the default?

I am asking this because i have an application in c# who works with sql server databases and if you want to connect to a non-default instance we specify in the connection string the computer name and the instance name, but if we want to specify the default instance we only have to specify the computer name.

But how can i know which one of all instances (if we have more than one) is the default?

I use this method to find all the servers and the instances...

SqlDataSourceEnumerator dtSrcServs = SqlDataSourceEnumerator.Instance;
Datatable dtTableServs = dtSrcServs.GetDataSources();
3
  • 1
    In what respect? Do you mean which binaries of MSSQL.1 etc to look for? There is no "default" as such: it's just one of the SQL Server installs that listens on port 1433 and has no instance name. That is, if you connected using servername only and you had only "named instances", then you'd fail to connect
    – gbn
    Feb 5, 2011 at 14:57
  • So the no named instance is always the default??
    – Miguel
    Feb 6, 2011 at 1:43
  • Thanks. I'm a beginner and i am learning how to work with SQL. The problem is in my college, in their network, i detect more than 50 computers, and each of them with more than one instance, but the problem is because they have a SQL Express instance as default but is a named instance, but if i want to connect to it, i can't specify the name of the instance because if i do it, it won't work. The problem is that if i want to connect to it, i have to ignore it's name, and only specify the name of the computer.
    – Miguel
    Feb 8, 2011 at 8:21

1 Answer 1

1

Generally, the first installation on the server (of 2000 or 2005) will be the default install, i.e. You can connect to it via the computer name with the need to add an instance.

You find the instance name by running SELECT @@Version, however, you'd need to already know the instance name to have connected. Therefore... You can use the registry to determine the named instances on your server by going to

HKLM\software\Microsoft\Microsoft SQL server\Instance Names\SQL

Once you have them, try connecting to them using the Server_Name\Instance_Name

see these links

link1

link2

1
  • The reg entries for SQL 2000 and 2005 are different. The first installation can be named or default. You don't enumerate instances from the registry to connect.
    – gbn
    Feb 5, 2011 at 15:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.