如何在局域网里搜索SQL服务器的信息,比如服务器名称

解决方案 »

  1.   

    这是Delphi的,你看看
    procedure TForm1.FormCreate(Sender: TObject);
    var
      SQLServer:Variant;
      ServerList:Variant;
      i,nServers:integer;
    begin
     SQLServer := CreateOleObject('SQLDMO.Application');
     ServerList:= SQLServer.ListAvailableSQLServers;
     if serverlist.count<1 then
      begin //如果服务器不存在,则退出系统
         showmessage('服务器不存在,请检测服务器是否已经开机或者服务是否打开了');
         application.Terminate;
      end
     else
      begin
       for i:=1 to serverlist.count do
       listbox1.Items.Add(serverlist.item(i)) ;
    //   showmessage(serverlist.item(1)+'服务器已经打开,可以正常使用本系统');
    //   adoconn.close;
    //   adoconn.ConnectionString:='Provider=SQLOLEDB.1;Persist Security info=False;UserID=sa;InitialCatalog=ideal_db;DataSource='+ServerList.Item(1);
      end;
     SQLServer:=NULL;
     serverList:=NULL;end;
      

  2.   

    Two Method!
    Use SQL DMO!
      

  3.   

    1>>'Add the reference of micorsoft sqldmo object library
    'Add a Combox(cboServer) on the Form
    Private Sub Form_Load()    Dim oApplication As New SQLDMO.Application
        Dim oServerGroup As SQLDMO.ServerGroup
        Dim oRegisteredServer As SQLDMO.RegisteredServer
        
        cboServer.Clear
        ' Process all the server groups
        For Each oServerGroup In oApplication.ServerGroups
            ' Process each registered server
            For Each oRegisteredServer In oServerGroup.RegisteredServers
                ' Add each name to the combobox
                cboServer.AddItem oRegisteredServer.Name
            Next
        Next
        
        Set oRegisteredServer = Nothing
        Set oServerGroup = Nothing
        Set oApplication = Nothing
        
    End Sub
      

  4.   

    'Note To upper Method
    'Add the Following Code
    cboServer.Listindex=0 '(the Server Exist)2>>
    'Add the reference of micorsoft sqldmo object library
    'Add a Combox(cboServer) on the FormPrivate Sub Form_Load()
        
      Dim oSQLServerDMOApp As SQLDMO.Application
      Set oSQLServerDMOApp = New SQLDMO.Application
      Dim i As Integer
      Dim namX As NameList
      Set namX = oSQLServerDMOApp.ListAvailableSQLServers
      For i = 1 To namX.Count
        cboServer.AddItem namX.Item(i)
      Next
      'Show top server
      cboServer.ListIndex = 0  Set namX = Nothing
      Set oSQLServerDMOApp = Nothing
    End Sub
    //
    http://expert.csdn.net/Expert/topic/1162/1162450.xml?temp=.2607538