Jump to content

Connection to the database by ini file


andersonrsbezerra

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;
Link to comment
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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...