I have developed an application that uses RAD Server over IIS. So far I have successfully created my Server and client applications. The app provides some information that needs to be verified against a MSSQL database on the Server Side. Everything works fine in a test environment as my Database Connection parameters are set in my FDConnection component.
However, I would like to change the Connection parameters by reading an ini file when the Server is accessed.
On my development system I can place the ini file in the directory where my bpl output is located. (ie. C:\Users\Username\Projects\Application\Server\Win32\Debug). The server then reads the ini file correctly and updates the component parameters.
I have created the directories on the server in accordance with the RAD Server documentation and have placed the required EMS files in the directory. (ie: C:\inetpub\RADServer\EMSServer) Since this is where the emsserver.ini file resides, I thought this would be the correct place to put my ini file. If I launch the EMSDevServer.exe from this directory, the ini file gets read properly and FDConnection parameters get updated.
However, when I launch the RAD Server through IIS using the ISAPI dlls, it appears the ini file is not found as my database connections fail.
I have tried putting the ini file in the C:\Users\Public\Documents\Embarcadero\EMS directory and that did not work either.
Following is my code to access the ini file which is called on DataModuleCreate.
procedure TdmSecurity.DataModuleCreate(Sender: TObject);
begin
SetConnectionStr(FDConnectionSTIKS);
end;
procedure SetConnectionStr(var FDConnectionSTIKS: TFDConnection);
var ConfigIni: TInifile;
DBServerName, DBName, Path: string;
begin
Path := GetCurrentDir;
ConfigIni := TIniFile.Create(System.IOUtils.TPath.Combine(Path, 'Config.ini'));
// ConfigIni := TIniFile.Create(System.IOUtils.TPath.Combine(System.IOUtils.TPath.GetDocumentsPath, 'Config.ini'));
// ConfigIni := TIniFile.Create('C:\Users\leonard\Projects\LumberNowEMS\Server\Win32\Debug\config.ini');
DBServerName := ConfigIni.ReadString(AppNode, 'ServerName', 'ZEUS');
DBName := ConfigIni.ReadString(AppNode, 'DataBase', 'NOTHING');
// showmessage(configini.FileName);
with FDConnectionSTIKS.Params as TFDPhysMSSQLConnectionDefParams do
begin
DriverID := 'MSSQL';
Server := DBServerName;
Database := DBName;
UserName := DBUserID;
Password := DBPassword;
end;
ConfigIni.Free;
// showmessage(Path + '; DBName:' +DBName);
// Result := Format('DriverID=MSSQL;Server=%s;Database=%s;User_name=%s;Password=%s', [DBServerName, DBName, DBUserID, DBPassword]);
end;
I expected that the IIS would read the ini file from the same place but it does not appear to be so. Can someone tell me where I should put the ini file so IIS can access it correctly or perhaps a better way of setting the database connection in Rad Server? Perhaps I could put my parameters in the emsserver.ini if there is a variable I can access.