想用VB做获取局域网内所有SQL服务器列表的功能,不知能否实现?

运行:osql -L --参数必须大写

VB:
function TFormDataSet.GetSQLServer(ComboBox: TComboBox): Boolean;
var
SQLServer: Variant;
ServerList: Variant;
i, nServers: integer;
sRetValue: string;
begin
ComboBox.Items.Clear;
Result := False;
try
Screen.Cursor := crHourGlass;
SQLServer := CreateOleObject('SQLDMO.Application');
ServerList := SQLServer.ListAvailableSQLServers;
nServers := ServerList.Count;
for i := 1 to nServers do
ComboBox.Items.Add(ServerList.Item(i));
SQLServer := NULL;
ServerList := NULL;
Result := True;
cbSQLServer.Style := csDropDownList;
except
end;
Screen.Cursor := crDefault;
end;

c++得到:
Variant SQLServer;
Variant ServerList;
int i,nServers;
String sRetValue;
try
{
SQLServer = CreateOleObject("SQLDMO.Application");
}
catch(...)
{
ShowMessage("需要SQL Server客户端软件支持...");
return;
}

ServerList= SQLServer.OleFunction("ListAvailableSQLServers");
nServers=ServerList.OlePropertyGet("Count");
for(i=1;i<=nServers;i++)
ValueListEditor1->InsertRow( IntToStr(i), ServerList.OleFunction("Item", i), 1);
SQLServer=Unassigned;
ServerList=Unassigned;

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus