Here's the code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
procedure TOpenSQLServerForm.DatabasesOnServer(Databases : TStrings); | |
var | |
rs : _RecordSet; | |
begin | |
Databases.Clear; | |
with TAdoConnection.Create(nil) do | |
try | |
//simple ConnectionString without the DB name | |
ConnectionString := ConnStr; | |
LoginPrompt := False; | |
try | |
Open; | |
rs := ConnectionObject.OpenSchema( | |
adSchemaCatalogs, | |
EmptyParam, | |
EmptyParam); | |
with rs do | |
begin | |
try | |
Databases.BeginUpdate; | |
while not Eof do | |
begin | |
Databases.Add( | |
VarToStr(Fields['CATALOG_NAME'].Value)); | |
MoveNext; | |
end; | |
finally | |
Databases.EndUpdate; | |
end; | |
end; | |
Close; | |
except | |
on e:exception do | |
MessageDlg(e.Message,mtError, [mbOK],0); | |
end; | |
finally | |
Free; | |
end; | |
end; |
Komentar