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.
There are quite a few options how to find those in code - see:
Locate SQL Server instances on the local network - uses the UDP protocol and sockets to find SQL Server on a LAN
Enumerating Instances of SQL Server (ADO.NET) - uses ADO.NET and a SqlDataSourceEnumerator to find SQL Servers and returns a DataTable with info about them
There are quite a few more ways to find your SQL Servers - do these options work for you??
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With