//获得网上有效的SQLServer
//调用SQLDMO的ListAvailableSQLServers()方法
System.Console.WriteLine("Searching SQL Server on the network...");  
try
{
SQLDMO.Application app=new SQLDMO.ApplicationClass();
foreach(string svrname in app.ListAvailableSQLServers())
{
System.Console.WriteLine(svrname);   
}
}
catch(Exception e)
{
System.Console.WriteLine(e.Message);   
}
System.Console.WriteLine("Searching ended");
//结束

解决方案 »

  1.   

    SQLDMO.ListAvailableSQLServers
    ListAvailableSQLServers Method
    The ListAvailableSQLServers method returns a NameList object that enumerates network-visible instances of Microsoft® SQL Server™ 2000.Applies ToApplication Object 
    Syntax
    object.ListAvailableSQLServers( ) as NameListParts
    objectExpression that evaluates to an object in the Applies To listPrototype (C/C++)
    HRESULT ListAvailableSQLServers(
    LPSQLDMONAMELIST* ppServerNames);Returns
    A NameList object that enumerates instances of SQL Server.Res
    Nondefault instances of SQL Server are displayed in the form of SERVERNAME/INSTANCENAME.The ListAvailableSQLServers method is supported only for servers and workstations running Microsoft Windows NT® 4.0 and Microsoft Windows 2000.Note  ListAvailableSQLServers maps to the ODBC SQLBrowseConnect function, which does not support connection pooling. Therefore, an application that enables connection pooling might encounter the error "Microsoft SQL-DMO (0x800A000E) [SQL-DMO]Not enough storage is available to complete this operation." when calling ListAvailableSQLServers.
      

  2.   

    谢谢enhydraboy(乱舞的浮尘) 。