Jump to content
uniGUI Discussion Forums
Sign in to follow this  
andersonrsbezerra

Connection to the database by ini file

Recommended Posts

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;

Share this post


Link to post
Share on other sites

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;
 

  • Upvote 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×