Board index » delphi » List server database

List server database


2003-09-10 03:47:38 PM
delphi132
Hello,
I would like to do a combo witch contains the list of database's available
on a server like Enterprise Manager(sqlserver) do it.
How can I do that ?
thanks with friendly
 
 

Re:List server database

One week ago same question was posted here. Answer is:
****************************************
You may use SQLDMO automation:
procedure GetAvailableServers (var lstServers: TStrings);
var
objDMO, objList: OleVariant;
i: Integer;
begin
lstServers.Clear;
objDMO := CreateOleObject('SQLDMO.Application');
objList := objDMO.ListAvailableSQlServers;
for i := 1 to objList.Count do
lstServers.Add(objList.Item(i));
objList := UnAssigned;
objDMO := UnAssigned;
end;
****************************************
"david" <XXXX@XXXXX.COM>сообщи?сообщила ?новостях следующе?
Quote
Hello,
I would like to do a combo witch contains the list of database's available
on a server like Enterprise Manager(sqlserver) do it.
How can I do that ?

thanks with friendly


 

Re:List server database

Hi David,
Here's some example code:
function TdmMain.GetDatabases(ParentScopeItem: TScopeItem) : Boolean ;
Var
Db : TDmoDatabase ;
DmoServer : TDmoServer ;
I : Integer ;
NewScopeItem : TScopeItem ;
begin
DmoServer := TDmoServer(ParentScopeItem.Data) ;
ParentScopeItem.ScopeItems.Items[0].ScopeItems.Clear ;
Result := True ; // Assume that a connection can be made to the server.
If DmoServer.Connect Then
For I := 0 to Pred(DmoServer.Databases.Count) Do Begin
Db := DmoServer.Databases[I] ;
End
Else
Result := False ; // A connection couldn't be established.
end;
Adjust for your own purposes. I hope that helps you.
Richard Rogers.
 

Re:List server database

There is a stored procedure in sql server
exec sp_databases to call it
Peppe Lo Verso
"david" <XXXX@XXXXX.COM>ha scritto nel messaggio
Quote
Hello,
I would like to do a combo witch contains the list of database's available
on a server like Enterprise Manager(sqlserver) do it.
How can I do that ?

thanks with friendly


 

Re:List server database

select * from [master].[dbo].[sysdatabases]
 

Re:List server database

I have tried this -- but the count returns 0
though I have a local MS SQL server running!
//--
procedure TForm1.Button1Click(Sender: TObject);
var
objDMO, objList: OleVariant;
i: Integer;
begin
ComboBox1.Clear;
objDMO := CreateOleObject('SQLDMO.Application');
objList := objDMO.ListAvailableSQlServers;
{count is 0!}
for i := 1 to objList.Count do
ComboBox1.Items.Add(objList.Item(i));
{I get nothing in to the ComboBox!}
objList := UnAssigned;
objDMO := UnAssigned;
end;
//--
What am I missing here!?
Thanks in advance,
Sarah
"Mike Shkolnik" <XXXX@XXXXX.COM>writes
Quote
One week ago same question was posted here. Answer is:
****************************************
You may use SQLDMO automation:

<snip>