Finding the correct connection string for a local SQL instance

I am trying to build a connection string for a test environment that will connect to a local instance of SQL Server on different computers. The purpose of this is so that the developer can check the code from TFS, build it and run test windows by connecting to its local database. The problem is that there may be different SQL Server settings on different development machines. In particular, some may work on a full server, others may work with SQL Server Express.

I am trying to configure a utility that will use the template connection string (for example Data Source=(local); Initial Catalog= myDB; Integrated Security=SSPI;) and change the data source to work with the local server.

I tried using SmoApplication.EnumAvailableServers()(returns an empty table, regardless of whether I are true or false user parameters) and SqlDataSourceEnumerator.GetDataSources()(returns 2888 servers from the network, but none on the local machine), SQLCMD -L(returns nothing).

Any suggestions?

Alternatively, is there an easy way to determine if a particular connection string will connect to the server (without waiting for it to time out, if it is not). If I could find the answer to this question, I could try probable suspects until I find it for work.

+3
source share
4 answers

you can try to get the connection string as follows:

  • Create a new empty file and name it test.udl.

  • , " ".

  • "" "Microsoft OLE DB Provider SQL Server" " SQL"

  • "" " ", . "", .

  • test.udl "" , "Provider =", "ConnectionString" Web.config, , "Provider = SQLNCLI.1;"

+2

, SQL-, ADO , localhost

... ; Data Source=localhost; ...

, ,

osql -L
+1

:

Data Source=.\SQLEXPRESS
0

, SQL Server. : HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL.

. . MSSQLSERVER.

0

All Articles