Jump to content


Photo

Connection to the database by ini file


  • Please log in to reply
2 replies to this topic

#1 andersonrsbezerra

andersonrsbezerra

    Member

  • Members
  • PipPip
  • 15 posts

Posted 10 January 2018 - 01:59 PM

Good Morning,
How to connect to the database by INI file?


  • 0

#2 Alberto vesx

Alberto vesx

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 475 posts

Posted 10 January 2018 - 03:27 PM

This is a very simple way to do it.

uses
  IniFiles;
...

var
  conf: Tinifile;

begin

  conf := Tinifile.Create(ChangeFileExt(Application.ExeName,'.ini'));  

  try
    try  
      datamodule.uconnexion.server := conf.ReadString('CONNEXION', 'IP', 'ERROR');
      datamodule.uconnexion.Database := conf.ReadString('CONNEXION', 'dbname', 'ERROR');
      datamodule.uconnexion.Username := conf.ReadString('CONNEXION', 'username', 'ERROR');
      datamodule.uconnexion.Password := conf.ReadString('CONNEXION', 'password', 'ERROR');

      If (dm.uconnexion.host = 'ERROR') or (dm.unicon.Database = 'ERROR') or (dm.unicon.Username = 'ERROR') or (dm.unicon.Password = 'ERROR')
         or (dm.uconceccdir.Database = 'ERROR') or (dm.uconceccdir.Username = 'ERROR') or (dm.uconceccdir.Password = 'ERROR') then
      begin
        showmessage('Bad file configuration or program name has changed');
        abort;
      end; 
 
      datamodule.connexion.connect;

    except
   
    end;
  Finally
    conf.Free;
  end;
end;

  • 0

#3 adragan

adragan

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 159 posts

Posted 12 January 2018 - 08:21 PM

If you intend to make it a ISAPI module this is better :

 

procedure ........

  var
        fname:string;
          ini:TIniFile;
  begin

 

  // Put your configuration in a different folder as the root , as in this case I used .\etc

  fname:=UniServerModule.StartPath+'etc\your_conf_name.conf';
  if FileExists(fname) then
     begin

     .............  Here is the same as in the previous answer ...............

 

 

     end;
 


  • 1




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users