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?