参考
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2595469
标题是: 怎样利用程序自动获取安装SQLserver服务器的名称?
贴的主人说不行,不过我测了还可以,其中方法一需要sqldmo,而这个东西需要的包是如下的部分(摘在Sql的帮助),关键还是sqldmo.dll
Installing SQL-DMO
All required SQL-DMO components are installed as part of an instance of Microsoft® SQL Server™ server or client. SQL-DMO is implemented in a single dynamic-link library (DLL). You may develop SQL-DMO applications on either a client or a server. When using an OLE Automation controller as a development platform, such as Microsoft Visual Basic®, no additional files are required. Application development using C or C++ requires the SQL-DMO header files.
SQL-DMO sample applications, providing additional reference material for SQL-DMO application development, are included with SQL Server.
Directory File Description
C:/Program Files/Microsoft SQL Server/80/Tools/Binn Sqldmo.dll DLL implementing SQL-DMO objects.
C:/Program Files/Microsoft SQL Server/80/Tools/Binn Sqldmo80.hlp SQL-DMO help file used within the development environment to provide context sensitive help about SQL-DMO objects, properties and methods.
C:/Program Files/Microsoft SQL Server/80/Tools/Binn/
Resources/xxxx Sqldmo.rll Localized resource file. The resource directory varies based on the national language of the instance of SQL Server client or server. For example, the directory 1033 is a decimal representation of the language identifier 0X0409, indicating English, U.S.
C:/Program Files/Microsoft SQL Server/80/Tools/
Devtools/Include Sqldmo.h C/C++ header file containing SQL-DMO member function prototypes, enumerated data types, and macros.
C:/Program Files/Microsoft SQL Server/80/Tools/
Devtools/Include Sqldmoid.h C/C++ header file containing SQL-DMO interface and class identifiers.
/Program Files/Microsoft SQL Server/MSSQL/Install Sqldmo.sql Transact-SQL script implementing stored procedures that support SQL-DMO. Available on SQL Server server-instance only.
C:/Program Files/Microsoft SQL Server/80/Tools/
Devtools/Samples/Sqldmo ALL Sample applications illustrating SQL-DMO use.
To register the SQL-DMO components on a client computer (需要注册的组件)
From C:/Program Files/Microsoft SQL Server /80/Tools/Binn/Resources/<language> directory, execute:
/Program Files/Microsoft SQL Server /80/Tools/Binn/REGSVR32 SQLDMO.DLL
From any directory, execute:
C:/Program Files/Microsoft SQL Server /80/Tools/Binn/REGSVR32.EXE
C:/Program Files/Microsoft SQL Server /80/Tools/Binn/resources/1033/SQLDMO.RLL
方法二是windows的api函数,这两种应该都不需要特别安装客户端,供楼主参考
-----------------------转自网络
获取SQL Server服务器列表的几种方法
一、SQL DMO
描述:SQL Distributed Management Objects(SQL分布式管理对象),存在于SQLDMO.dll文件中,实际上是一个COM 对象,通过调用SQL DMO的ListAvailableSQLServers方法取得。
列表类型:列举装有“客户端”和“服务端”的计算机。
适用条件:装有 SQL Server,且有SQLDMO.dll文件。
速度:中
调用示例:GetSQLServerList(ListBox1.items);
代码:
uses
ComObj;
function GetSQLServerList(var AList: TStrings): Boolean;
var
SQLServerApp: Variant;
ServerList: Variant;
i: Integer;
begin
Result := True;
try
SQLServerApp := CreateOleObject('SQLDMO.Application');
ServerList := SQLServerApp.ListAvailableSQLServers;
for i := 1 to ServerList.Count do
AList.Add(ServerList.Item(i));
SQLServerApp := Unassigned;
ServerList := Unassigned;
except
Result := False;
end;
end;
二、NetServerEnum
描述:网络服务函数,存在于NetApi32.dll文件中;通过NetServerEnum函数可取得装有SQL Server服务端的计算机列表,只装有SQL Server客户端的计算机将不会被列举其中;如果一台计算机的SQL Server服务刚刚启动,那么此函数将会过很久才能取到该计算机。
列表类型:仅列举装有“服务端”的计算机。
适用条件:有NetApi32.dll文件。
速度:快
调用示例:GetSQLServerList(ListBox1.items);
代码:
type
NET_API_STATUS = DWORD;
PServerInfo100 = ^TServerInfo100;
_SERVER_INFO_100 = record
sv100_platform_id: DWORD;
sv100_name: LPWSTR;
end;
{$EXTERNALSYM _SERVER_INFO_100}
TServerInfo100 = _SERVER_INFO_100;
SERVER_INFO_100 = _SERVER_INFO_100;
{$EXTERNALSYM SERVER_INFO_100}
const
NERR_Success = 0;
MAX_PREFERRED_LENGTH = DWORD(-1);
SV_TYPE_SQLSERVER = $00000004;
function NetApiBufferAllocate(ByteCount: DWORD; var Buffer: Pointer):
NET_API_STATUS; stdcall; external 'netapi32.dll' name 'NetApiBufferAllocate';
function NetServerEnum(ServerName: LPCWSTR; Level: DWORD; var BufPtr: Pointer;
PrefMaxLen: DWORD; var EntriesRead: DWORD; var TotalEntries: DWORD;
ServerType: DWORD; Domain: LPCWSTR; ResumeHandle: PDWORD): NET_API_STATUS;
stdcall; external 'netapi32.dll' name 'NetServerEnum';
function NetApiBufferFree(Buffer: Pointer): NET_API_STATUS; stdcall; external
'netapi32.dll' name 'NetApiBufferFree';
function GetSQLServerList(var AList: TStrings; pwcServerName: PWChar = nil;
pwcDomain: PWChar = nil): Boolean;
var
NetAPIStatus: DWORD;
dwLevel: DWORD;
pReturnSvrInfo: Pointer;
dwPrefMaxLen: DWORD;
dwEntriesRead: DWORD;
dwTotalEntries: DWORD;
dwServerType: DWORD;
dwResumeHandle: PDWORD;
pCurSvrInfo: PServerInfo100;
i, j: Integer;
begin
Result := True;
try
dwLevel := 100;
pReturnSvrInfo := nil;
dwPrefMaxLen := MAX_PREFERRED_LENGTH;
dwEntriesRead := 0;
dwTotalEntries := 0;
dwServerType := SV_TYPE_SQLSERVER; //服务器类型
dwResumeHandle := nil;
NetApiBufferAllocate(SizeOf(pReturnSvrInfo), pReturnSvrInfo);
try
NetAPIStatus := NetServerEnum(pwcServerName, dwLevel, pReturnSvrInfo,
dwPrefMaxLen, dwEntriesRead, dwTotalEntries, dwServerType, pwcDomain,
dwResumeHandle);
if ((NetAPIStatus = NERR_Success) or (NetAPIStatus = ERROR_MORE_DATA)) and
(pReturnSvrInfo <> nil) then
begin
pCurSvrInfo := pReturnSvrInfo;
// 循环取得所有SQL Server服务器
i := 0;
j := dwEntriesRead;
while i < j do
begin
if pCurSvrInfo = nil then
Break;
with AList do
Add(pCurSvrInfo^.sv100_name);
Inc(i);
Inc(pCurSvrInfo);
end;
end;
finally
if Assigned(pReturnSvrInfo) then
NetApiBufferFree(pReturnSvrInfo);
end;
except
Result := False;
end;
end;
三、SQLBrowseConnect
描述:ODBC函数(Microsoft Open Database Connectivity,开放式数据库互接),存在于odbc32.dll文件中;通过SQLBrowseConnect函数可返回连接字符串信息,包括DSN、DRIVER、SERVER、UID、PWD、APP、WSID、DATABASE、LANGUAGE等信息。在函数GetODBCInfo 中传入itServer、itDatabase、itLanguage可分别取得“服务器”、“数据库”及“语言”等信息列表,其中itDatabase、itLanguage默认取本地信息,取远程信息请自行修改“