SQL/MSDE Find all available servers

  • Thread starter Thread starter Wardeaux
  • Start date Start date
W

Wardeaux

All,
I'm trying to ensure that I only have one named instance of my MSDE DB on
the network, so I want to get a list of all available server names and check
to see if mine is already listed... what is the best approach to do this?
MTIA
wardeaux
 
SQL-DMO or SQL-NS. DMO is usually the easiest for simply enumerating
servers. But, DMO is not available in .NET currently.

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

************************************************
Think Outside the Box!
************************************************
 
Greg,
Thanks! Is there a good sample on how to do this with the .NET flavor?
What are there some key words I can search on (that won't give me 500 hits)?
Thanks again!
wardeaux
 
Ah, I write SQL-DMO examples all the time with .NET. I'll be demonstrating
same in my session at the SQL Connections conference in November (Vegas).
It's a COM interface and not built into .NET, but you can still call it. The
..NET version is called SMO and it ships with Yukon.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
SQL-DMO or SQL-NS. DMO is usually the easiest for simply enumerating
servers. But, DMO is not available in .NET currently.

Well, yes it is - just import a reference to the COM "SQL-DMO" type
library, and off you go!

Once you've done this, this will return a list of available SQL (and
MSDE) servers:

public ArrayList EnumerateServers()
{
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++)
{
// make sure we're not adding a Server twice!
if (!alsServers.Contains(oNames.Item(i)))
{
alsServers.Add(oNames.Item(i));
}
}
oNames = null;
oSQLApp = null;
}
catch { // handle exception as you see fit}

return alsServers;
}


Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
No samples for .NET that I know of, but you can install the SQL Server
samples from the SQL Server install media and see the COM version. As you
will have to use Interop, the method of querying will be the same in both
COM and .NET. Just remember you will have to add a COM reference to get the
DMO library.

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

************************************************
Think Outside the Box!
************************************************
 
SMO is very cool. Until that day, we deal with DMO. I am not fond of
marshalling through Interop, but enumerating servers is not a major deal,
perf wise, as you do not do it all the time.

I think Wardeaux is looking for samples, if you have any published. I have
played with DMO in COM, but not in .NET (no need thus far).

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

************************************************
Think Outside the Box!
************************************************
 
Back
Top