Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / May 2005

Tip: Looking for answers? Try searching our database.

How do you enumerate SQL Servers in .NET

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian Kitt - 05 May 2005 18:55 GMT
I would like my application to be able to enumerate all available SQL servers
for the user to pick where they want the database created.  The Wizard for
Sql data access does this.  I just want to enumerate a list so I can put them
in a drop down box.  I'm really at a loss of where to go to get this list.  I
assume WMI would provide it, but is that the best way.  And if so, what class
is it in?
Marc Scheuner [MVP ADSI] - 06 May 2005 06:49 GMT
>I would like my application to be able to enumerate all available SQL servers
>for the user to pick where they want the database created.  
>I just want to enumerate a list so I can put them in a drop down box.  

I'd use SQL-DMO - just add a reference to the COM object "Microsoft
SQLDMO Object Library" (sqldmo.dll) and then you're good to go:

public ArrayList FillListOfServers()
{
    ArrayList alsServers = new ArrayList();
   
    SQLDMO.NameList oNames;
    SQLDMO.Application oSQLApp;

    try
    {
        oSQLApp = new SQLDMO.Application();
        oNames = oSQLApp.ListAvailableSQLServers();

        for (int i = 1; i <= oNames.Count; i++)
        {
            if (!alsServers.Contains(oNames.Item(i)))
            {
                alsServers.Add(oNames.Item(i));
            }
        }
        oNames = null;
        oSQLApp = null;
    }
    catch
    {
        // handle exception
    }
}

SQL-DMO is installed as part of SQL Server, when you install it on
your machine.

Marc
Cowboy (Gregory A. Beamer) - MVP - 06 May 2005 16:42 GMT
Use DMO and Interop. Once SQL Server 2005 is out, you will be able to use SMO
in .NET, but DMO and Interop is the only way right now. You will have to
create a .NET wrapper to call the DMO classes.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************

> I would like my application to be able to enumerate all available SQL servers
> for the user to pick where they want the database created.  The Wizard for
> Sql data access does this.  I just want to enumerate a list so I can put them
> in a drop down box.  I'm really at a loss of where to go to get this list.  I
> assume WMI would provide it, but is that the best way.  And if so, what class
> is it in?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.