This is the way I know how to connect using a FDConnection
Change the data according to what you need
unit FiredacPooling;
interface
uses
FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf,
FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async,
FireDAC.Phys, FireDAC.Phys.MySQL, FireDAC.Phys.MySQLDef, FireDAC.Stan.Param,
FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, Data.DB, FireDAC.Comp.DataSet,
FireDAC.Comp.Client, Classes, IniFiles;
type
TFireDacPooling = class
private
FConnection : TFDConnection;
function CarregaConfiguracoes(cChave, cSubChave: String; cValorPadrao: string = ''): Variant;
procedure AtualizarConfiguracoes(cChave, cSubChave: String; cValor: string = '');
public
constructor Create;
destructor Destroy; override;
end;
var
DBPool : TFireDacPooling;
implementation
{ TFireDacPooling }
constructor TFireDacPooling.Create;
{var
Params: TStringList;}
begin
{Params := TStringList.Create;
try
//Params.Add('User_Name=sa');
//Params.Add('Password=1');
//Params.Add('Server=127.0.0.1');
Params.Add('Server=DESKTOP-3RKGJ2M');
Params.Add('OSAuthent=Yes');
Params.Add('Database=Pangya');
Params.Add('Pooled=True');
Params.Add('POOL_MaximumItems=1000');
FConnection := TFDManager.Create(nil);
FConnection.AddConnectionDef('MSSQLPool', 'MSSQL', Params);
finally
Params.Free;
end;}
with(FConnection)do
begin
if(Connected)then
Connected := False;
Params.Values['DriverID'] := 'MSSQL';
Params.Values['Database'] := CarregaConfiguracoes('ChavePrincipal', 'ChaveSecundaria'); {Pangya}
Params.Values['User_Name'] := CarregaConfiguracoes('ChavePrincipal', 'ChaveSecundaria'); {sa}
Params.Values['Password'] := CarregaConfiguracoes('ChavePrincipal', 'ChaveSecundaria'); {1}
Params.Values['Pooled'] := True;
Params.Values['POOL_MaximumItems'] := 1000;
Params.Values['OSAuthent'] := True;
Params.Values['Server'] := CarregaConfiguracoes('ChavePrincipal', 'ChaveSecundaria'); {DESKTOP-3RKGJ2M}
Connected := True;
end;
end;
destructor TFireDacPooling.Destroy;
begin
FConnection.Free;
inherited;
end;
function TFireDacPooling.CarregaConfiguracoes(cChave, cSubChave: String; cValorPadrao: string = ''): Variant;
var
oConfig: TIniFile;
begin
Result := ''; {Carrega o arquivo .ini, mas para isso o mesmo precisa estar no mesmo diretório do EXE}
oConfig := TIniFile.Create(ExtractFileDir(ExtractFilePath(ParamStr(0))) + '\SeuArquivo.ini');
try
Result := oConfig.ReadString(cChave, cSubChave, cValorPadrao);
finally
oConfig.Free;
end;
end;
procedure TFireDacPooling.AtualizarConfiguracoes(cChave, cSubChave: String; cValor: string = '');
var
oConfig: TIniFile;
begin {Escreve no arquivo .ini, mas para isso o mesmo precisa estar no mesmo diretório do EXE}
oConfig := TIniFile.Create(ExtractFileDir(ExtractFilePath(ParamStr(0))) + '\SeuArquivo.ini');
try
oConfig.WriteString(cChave, cSubChave, cValor);
finally
oConfig.Free;
end;
end;
initialization
DBPool := TFireDacPooling.Create;
finalization
DBPool.Free;
end.
Edited
In the file . INI there is the Key and the Subchave as in the example below:
[CHAVE]
subchave=valor
Your file would look +/- like this (The data I used is fictitious):
[CONEXAO]
Database=Pangya
User_Name=sa
Password=1
Server=127.0.0.1
[OUTROSDADOS]
subOutrosDados=tal
subOutrosDadosDois=
The method that is on the link is what you created to try to connect to the bank? Can you already read the file . ini? Explain a little better
– Matheus Ribeiro
no, my friend who made it for me lol
– LuisMK
i want that method read the ini file, and make the connection to bank
– LuisMK