1

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.

Leonard M.
  • 179
  • 3
  • 17
  • What value does the `Path` variable have when you are running under IIS? That will answer your question for you immediately. – Freddie Bell Jul 19 '19 at 05:27
  • Go to the root node from the Connections panel and double-click ISAPI and CGI Restrictions. Select Edit Features Settings from the Actions panel and check the two options [image](https://imgur.com/a/rVqU7Jj) and Return to the root node and double-click Handler Mappings. Go to the Actions panel, select Edit Feature Permissions and check Execute. [image1](https://imgur.com/a/p3EBGkL) could you please share the permisiion of the .ini file. in my opnion, you need to give IIS_iusrs and iusr full control. – Jalpa Panchal Jul 19 '19 at 09:14
  • 1
    @nolaspeaker - I don't know how to determine what the PATH variable contains when running IIS. I can't use showmessage() and I'm not sure how I show the value when it is contained in a package. When I run the EMSDevServer.exe the path variable is C:\inetpub\RADServer\EMSServer. I will see if I can write the value of the PATH variable to a text file. – Leonard M. Jul 19 '19 at 12:59
  • @JalpaPanchal I only loaded the ISAPI Extensions and not the CGI and have checked 'Allow unspecified ISAPI modules' at the root node. I enabled Execute permission on the RADServer node but not the Root node. I have since enabled Execute permission at the root node as well with no change in results. iUSR already has full permissions. – Leonard M. Jul 19 '19 at 13:53

2 Answers2

1

@nolaspeaker - I would give you credit for the answer but you only posted a comment. Your response prompted me to find a way to determine the path that was being used. So I wrote the value of the path variable to a known text file.

Path := GetCurrentDir;
AssignFile(F, 'C:\Temp\Data.txt');
Rewrite(F);
WriteLn(F, Path);
CloseFile(F);

The path that is being used is 'C:\Windows\SysWOW64\inetsrv';

I moved my Config.ini file to this directory and it was found and read correctly.

Thanks for the responses.

Leonard M.
  • 179
  • 3
  • 17
1

Quite late, still posting an answer.

Functions in System.SysUtils will be helpful here.

following function call would give you the path to the directory where the .bpl file resides.

ExtractFilePath(GetModuleName(HInstance));

place the ini along with .bpl file, combining the above function's result with the Ini filename will help you to target an ini.

A.Joe
  • 51
  • 6