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;
 

Comments

Popular posts from this blog

C# code to Check IE Proxy Settings

Convert XElement to DataTable