leons Posted November 22, 2016 Share Posted November 22, 2016 Hi, What is the best and secure way to store application settings like databaseconnection, password e.g. (like web.config or app.config, in .Net) regards Leon Link to comment Share on other sites More sharing options...
Skepsis IT Posted November 22, 2016 Share Posted November 22, 2016 Hi, You can create an ini file or a text file in general that has all the appropriate data that you connection component needs (Firedac, dbGo etc). Then retrieve and manipulate this file using UniServerModule.StartPath +'yourfilename.xxx' Regards Link to comment Share on other sites More sharing options...
Ron Posted November 22, 2016 Share Posted November 22, 2016 Right, and put it in the servermodule, and in the mainmodule onCreate as well if you need to. procedure TUniServerModule.UniGUIServerModuleCreate(Sender: TObject); var f:textfile; hostLine, portLine, dbLine, dbPortLine:string; cmdStr:string; procedure ExploreWeb(page:PChar); var Returnvalue: integer; begin ReturnValue := ShellExecute(0, 'open', page, nil, nil,SW_SHOWNORMAL); if ReturnValue <= 32 then begin case Returnvalue of 0 : MessageBox(0,'Error: Out of memory','Error',0); ERROR_FILE_NOT_FOUND: MessageBox(0,'Error: File not found','Error',0); ERROR_PATH_NOT_FOUND: MessageBox(0,'Error: Directory not found','Error',0); ERROR_BAD_FORMAT : MessageBox(0,'Error: Wrong format in EXE','Error',0); else MessageBox(0,PChar('Error Nr: '+IntToStr(Returnvalue)+' inShellExecute'),'Error',0) end; end; end; begin ServerRoot:=extractfilepath(GetModuleName(HInstance)); //read setup text file try assignfile(f, ServerRoot+'files/setup.txt'); reset(f); readln(f, hostLine); readln(f, portLine); readln(f, dbLine); readln(f, dbPortLine); closefile(f); except on E:Exception do ; end; case sslSetup of true: begin ssl.Enabled:=true; port:=443; end; false:begin ssl.Enabled:=false; port:=strtointdef(portLine, 8077); end; end; //connect db try with myDb do begin username:='user'; userpassword:='pass'; host:=hostLine; databasename:=dbLine; port:=strtointdef(dbPortLine, 3307); open; end; except on E:Exception do ; end; //load db setup data try loadSetup; except on E:Exception do ; end; //set app title title:=myLoadedSetupTitle; //close this db connection myDb.close; //autostart if standalone if self.StandAloneServer then begin cmdStr:='http://localhost:'+portLine; ExploreWeb(pchar(cmdStr)); end; end; Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now