Jump to content


Photo

Conectar banco de dados por um arquivo ini


  • Please log in to reply
1 reply to this topic

#1 andersonrsbezerra

andersonrsbezerra

    Member

  • Members
  • PipPip
  • 24 posts

Posted 10 January 2018 - 05:30 PM

Como realizar a conexão do banco de dados por um arquivo ini?

Quero colocar o código no OnCreate do MainModule

 


  • 0

#2 pedrisco

pedrisco

    Member

  • Members
  • PipPip
  • 29 posts

Posted 10 January 2018 - 07:50 PM

The file name is the application name plus ".ini", and its content is something like..

...

[database]

connectionString=SQLOLEDB.1;User ID=sa;Initial Catalog="database";Data Source=127.0.0.1,1433;Password=blahblehblih

 

 

 

Then i do something like this...

 

...

interface

...

type
  TUniMainModule = class(TUniGUIMainModule)
    ADOConn: TADOConnection;
    procedure UniGUIMainModuleCreate(Sender: TObject);

    ...
  end;

Implementation

...

Uses IniFiles, ...;

...

procedure TUniMainModule.UniGUIMainModuleCreate(Sender: TObject);
begin
    with TMemIniFile.Create(changeFileExt( paramStr(0) , '.conf' )) do begin
        AdoConn.close;
        AdoConn.connectionString    := ReadString('database','connectionString','');
        free;
    end;

    try
         ADOConn.open;
    ...

    end;
end;
 

 

Good luck


  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users