How we know which one of the sql server instances in a computer is the default?
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 instance开发者_StackOverflow中文版s (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();
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
精彩评论