andersonrsbezerra Posted January 10, 2018 Share Posted January 10, 2018 Good Morning,How to connect to the database by INI file? Quote Link to comment Share on other sites More sharing options...
albertovesx Posted January 10, 2018 Share Posted January 10, 2018 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; Quote Link to comment Share on other sites More sharing options...
adragan Posted January 12, 2018 Share Posted January 12, 2018 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.