Connection string for the default instance, for example, for a named instance

In my .NET application, I connect to a Microsoft SQL Server 2005 or 2008 database. The user selects an instance that shows the application, and then the application must do something with that instance. I take the instance names from the registry, HKLM \ Software \ Microsoft \ Microsoft SQL Server \ Instance Names \ SQL.

I do not know if the user selects a default instance instance or a named instance (and there is no such information in the instance name registry values). However, to connect to an arbitrary instance, I have to use either

Server=(local)

or

Server=MSSQLSERVER\instance_name

in my ADO.NET connection string. Can I use only one connection string template? I tried using Server = MSSQLSERVER \ MSSQL10.MSSQLSERVER for my default instance of SQL Server 2008, but the connection failed.

+3
source share
2 answers

If the instance name is MSSQLSERVER, you must use a type template Server=servername. For all other instance names, a template is used, for example Server=servername\instancename. You cannot explicitly specify a default instance name.

. , . -, , , , . , , SQL Browser .

- SQL Browser, , SmoApplication.EnumAvailableSqlServers.

+9

Server=servername\instance_name Server=address\instance_name

0

Source: https://habr.com/ru/post/1758924/


All Articles