|
|
Подразумевается, что будет визард для этих настроек, который будет сохранять их в ini файл рядом с exe. Но что делать, если этого визарда ещё нет, а подключиться надо ?
|
|
|
|
|
|
Для этого один раз выполняем такой код (на примере Postgre)
|
|
|
Для этого один раз выполняем такой код и закрываем программу
|
|
|
|
|
|
```
|
|
|
LPGConnectionSettings := Service<IConnectionSetting>();
|
|
|
LPGConnectionSettings.Ip := 'localhost';
|
|
|
procedure TDBFuncForm.SaveOracleSettingsConnString;
|
|
|
var
|
|
|
LOracleConnectionSettings: IConnectionSetting;
|
|
|
LSetting: ISections<IConnectionSetting>;
|
|
|
begin
|
|
|
// call it once and close program, settings will be saved in DBFunc.ini
|
|
|
LOracleConnectionSettings := Service<IConnectionSetting>;
|
|
|
LOracleConnectionSettings.ConnectionString := '(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST = 31.129.127.195)(PORT = 51521)))(CONNECT_DATA=(SERVICE_NAME=SHP0126.WORLD)))';
|
|
|
LOracleConnectionSettings.Login := 'shop';
|
|
|
LOracleConnectionSettings.Password := 'selectfromdual';
|
|
|
LOracleConnectionSettings.Name := 'SHP0126.WORLD';
|
|
|
LSetting := Service<ISections<IConnectionSetting>>;
|
|
|
LSetting.Add(LOracleConnectionSettings);
|
|
|
end;
|
|
|
|
|
|
procedure TDBFuncForm.SavePostgresSettings;
|
|
|
var
|
|
|
LPGConnectionSettings: IHostConnectionSetting;
|
|
|
LSetting: ISections<IHostConnectionSetting>;
|
|
|
begin
|
|
|
// call it once and close program, settings will be saved in DBFunc.ini
|
|
|
LPGConnectionSettings := Service<IHostConnectionSetting>();
|
|
|
LPGConnectionSettings.Host := 'localhost';
|
|
|
LPGConnectionSettings.Port := 5432;
|
|
|
LPGConnectionSettings.Login := 'login';
|
|
|
LPGConnectionSettings.Login := 'sbsmbroot';
|
|
|
LPGConnectionSettings.Password := '';
|
|
|
LPGConnectionSettings.Name := 'Postgres5432';
|
|
|
LSetting := Service<ISections<IHostConnectionSetting>>;
|
|
|
LSetting.Add(LPGConnectionSettings);
|
|
|
end;
|
|
|
|
|
|
LSettings := Service<TSettings>();
|
|
|
LSettings.Add('Postgres5432', LPGConnectionSettings);
|
|
|
LSettings := nil;
|
|
|
```
|
|
|
|
|
|
После этого наше подключение должно отработать нормально
|
|
|
`FConnectionPostgres := Service<IConnection>([], S_FD_PGId);` |
|
|
\ No newline at end of file |
|
|
```
|
|
|
// FConnectionPostgres := Service<IConnection>(['Postgres5432'], S_FD_PGId);
|
|
|
// if FConnectionPostgres.DBConnection.IsConnected then
|
|
|
// Caption := 'Connected';
|
|
|
|
|
|
// FConnectionOracle := Service<IConnection>(['SHP0126.WORLD'], S_FD_OraId);
|
|
|
// if (FConnectionOracle.DBConnection.IsConnected) then
|
|
|
// Caption := 'Connected';
|
|
|
``` |
|
|
\ No newline at end of file |