I know this is a very common issue and I found a lot of hints on this topic
in www but I did not find a very good solution for this task.
Most of the solutions use SQLDMO to list all sql servers in the network like
this C# code:
public static string[] GetAvailableSQL Servers()
{
// declare arraylist to hold results
ArrayList servers = new ArrayList();
// create and initialize necessary SQL access objects (see SQLDMO.dll)
SQLDMO.Applicat ionClass sqlApp = new SQLDMO.Applicat ionClass();
SQLDMO.NameList sqlServers = sqlApp.ListAvai lableSQLServers ();
for(int i=0;i<sqlServer s.Count;i++)
{
object srv = sqlServers.Item (i + 1);
if(srv != null)
{
servers.Add(srv .ToString());
}
}
// convert arraylist to string array and return it
return servers.ToArray (Type.GetType(" System.String") ) as string[];
}
But there are two main problems:
- this does not work with Windows XP (see SQLDMO documentation: it works
only with Windows NT 4.0 and 2000)
- it does not work on a local PC that is not connected to the network (it
does not show any instance that is available)
Does anybody have a better solution for this task?
in www but I did not find a very good solution for this task.
Most of the solutions use SQLDMO to list all sql servers in the network like
this C# code:
public static string[] GetAvailableSQL Servers()
{
// declare arraylist to hold results
ArrayList servers = new ArrayList();
// create and initialize necessary SQL access objects (see SQLDMO.dll)
SQLDMO.Applicat ionClass sqlApp = new SQLDMO.Applicat ionClass();
SQLDMO.NameList sqlServers = sqlApp.ListAvai lableSQLServers ();
for(int i=0;i<sqlServer s.Count;i++)
{
object srv = sqlServers.Item (i + 1);
if(srv != null)
{
servers.Add(srv .ToString());
}
}
// convert arraylist to string array and return it
return servers.ToArray (Type.GetType(" System.String") ) as string[];
}
But there are two main problems:
- this does not work with Windows XP (see SQLDMO documentation: it works
only with Windows NT 4.0 and 2000)
- it does not work on a local PC that is not connected to the network (it
does not show any instance that is available)
Does anybody have a better solution for this task?
Comment