3

Work on C#, in one of my application I need to get the SQL Server names. In network I have SQL Server 2000, 2005, 2008. For my application I want to get the server names.

private string strConnection = @"Data Source=xxx;Initial Catalog=xxx;Integrated Security=True";

SqlConnection objConnection = new SqlConnection(strConnection);
objConnection.Open();
SqlCommand objCommand = new SqlCommand(“xxxxxxx”);
objCommand.ExecuteNonQuery();
objConnection.Close();

If I know strConnection then I can use the above syntax. But I don’t know the server name. In my application first I need to know the server name. I need help to get the server names.

3 Answers 3

5

There are quite a few options how to find those in code - see:

There are quite a few more ways to find your SQL Servers - do these options work for you??

Sign up to request clarification or add additional context in comments.

1 Comment

+1 The ADO.NET utility class is very nice. I was thinking of nmaping and what not. :)
0

Take a look at Scan network for SQL Server instances to get some ideas about SQL Ping

Comments

0

You can use Use SmoApplication.EnumAvailableSqlServers method to Enumerate a list of available instances of SQL Server.

1 Comment

Works - but it requires SMO to be present which means a) either install the SQL Server Client Tools with SMO, or b) install SMO separately.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.