Using SMO
Here is the useful code to get the list of servers available on my network
using SMO.
DataTable dtSQLServers = SmoApplication.EnumAvailableSqlServers(false);
SQLServers.DataSource = dtSQLServers;
SQLServers.DataBind();
//Get the local server name
Server LocalServer = new Server();
String LocalServerName = LocalServer.Name;
//Check if the server has any instance, concatinate if an instance exists
if (LocalServer.InstanceName != null && LocalServer.InstanceName.Length > 0)
LocalServerName = @"\" + LocalServer.InstanceName;
DataTable dtSQLServers = SmoApplication.EnumAvailableSqlServers(false);
SQLServers.DataSource = dtSQLServers;
SQLServers.DataBind();
//Get the local server name
Server LocalServer = new Server();
String LocalServerName = LocalServer.Name;
//Check if the server has any instance, concatinate if an instance exists
if (LocalServer.InstanceName != null && LocalServer.InstanceName.Length > 0)
LocalServerName = @"\" + LocalServer.InstanceName;
Comments
Post a Comment