在Delphi下如何提取SQL Server完整列表
在Delphi下如何提取SQL Server完整列表,本文以代码形式提供了多种方法。
var
i:integer;
SQLServer: Variant;
ServerList: Variant;
begin
SQLServer:= CreateOleObject('SQLDMO.Application');
ServerList:= SQLServer.ListAvailableSQLServers;
for i := 1 to Serverlist.Count do
ComboBox1.Items.Add(Serverlist.item(i));
end;
或者不使用ComboBox控件的另一种方式:
Function GetSQLServerList(var List: Tstringlist): boolean;
var
i: integer;
sRetvalue: String;
SQLServer: Variant;
ServerList: Variant;
begin
Result := False;
List.Clear;
try
SQLServer := CreateOleObject('SQLDMO.Application');
ServerList := SQLServer.ListAvailableSQLServers;
for i := 1 to Serverlist.Count do
list.Add (Serverlist.item(i));
Result := True;
Finally
SQLServer := NULL;
ServerList := NULL;
end;
end;