๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #291

Re: How to find sql servers on lan

#291
From: Ruben Lopez
Date: Mon, 19 Jun 2006 07:28
67 lines
2783 bytes
void GetServers(TStrings*Lista)
{
   LPSQLDMOAPPLICATION pDMOApp = NULL;
	LPSQLDMONAMELIST pNameList = NULL;
   Lista->Clear();
   try{
		if SUCCEEDED(CoInitialize (NULL)){
   	  // Crear SQLDMOApplication.
		  if SUCCEEDED(CoCreateInstance(CLSID_SQLDMOApplication,
                                     NULL,
                                     CLSCTX_INPROC_SERVER,
                                     IID_IWSQLDMOApplication,
                                     (LPVOID*)&pDMOApp))
       {
         // Consultar lista de servidores
		    if SUCCEEDED(pDMOApp->ListAvailableSQLServers(&pNameList)){
			    long lCount=0;
			    BSTR strName=NULL;
			    //Numero de servidores
			    pNameList->GetCount(&lCount);

			    for(long i=0; i < lCount; i++){
				    //Nombre del servidor
				    pNameList->GetItemByOrd(i, &strName);
				    Lista->Add(strName);
			    }
		    }
		    if (pDMOApp){
			    pNameList = NULL;
			    pDMOApp->Release();
			    pDMOApp = NULL;
		    }
       }
     }
   }
   catch(...){
   }
}


You need this header files
#include <initguid.h>
#include <sqldmoid.h>
#include <sqldmo.h>

This I'm not sure.
#include <utilcls.h>


Thomas Goodson escribi๏ฟฝ:
> I didn't get a response in sqlservers, so I thought I'd try here.
> 
> Ok, I've got an application that works fine, but as part of deployment, I
> need to find all of the available MS-SQL / MSDE servers on the network and
> present a list to the installer.  (the list part I can handle)  I'm using
> ADO in the form of dbGo in BDS 2006 C++ mode.
> 
> I really don't want to use PromptDataSource since it offers the user WAY to
> many ways to shoot themselves in the foot.  (also, the database won't have
> been created yet).
> 
> So, how do I find the available SQL servers?
> 
> ** Tom **
> 
> 
> 
Technical Details
Message-ID: <44965203$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <44931de5@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,13a074f07b8e690
X-Google-Attributes: gid10698b,public
X-Google-Language: ENGLISH,ASCII
Date: Mon, 19 Jun 2006 09:28:11 +0200
From: Ruben Lopez <ruben.lopez@sica.es>
User-Agent: Thunderbird 1.5.0.4 (Windows/20060516)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.database.ado
Subject: Re: How to find sql servers on lan
References: <44931de5@newsgroups.borland.com>
In-Reply-To: <44931de5@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
NNTP-Posting-Host: 80.59.94.142
Message-ID: <44965203$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1150702083 80.59.94.142 (19 Jun 2006 00:28:03 -0700)
Lines: 67
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail