Wednesday, March 13, 2013

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;

        //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;

No comments:

Post a Comment