Question : Reading values from UDL-file (textfile)

Hi,

I would like to have a two functions that will read following values from a udl-file "myudl.udl" (like below)
Data Source        result = 'MYCOMPNAME\ServerInstance'
Initial Catalog     result = 'MyDBName'

1:
2:
3:
[oledb]
; Everything after this line is an OLE DB initstring
Provider=SQLOLEDB.1;Data Source=MYCOMPNAME\ServerInstance;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MyDBName;


How can this be done?

Answer : Reading values from UDL-file (textfile)

it's allways line 3 of the file
it's basically a delimited string
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
var FileName: string;
  List: TStrings;
  ds, ic: string;
begin
  FileName := 'C:\yourfilename.udl';
  List := TStringList.Create;
  try
    List.Delimiter := ';';
    List.StrictDelimiter := True;
    List.LoadFromFile(FileName);
    List.DelimitedText := List[2];
    ds := List.Values['Data source'];
    ic := List.Values['Initial catalog'];
    ShowMessage(ds + ' ' + ic);
  finally
    List.Free;
  end;
end;
Random Solutions  
 
programming4us programming4us