FIXING THE BAD GATEWAY ERROR IN IIS 7 AND LATER VERSIONS

INTRODUCTION:

SIOI and Webaccount systems use a program created in older versions of Delphi (up to v.7) to be able to generate reports in Crystal Reports 9. This program used to work fine in IIS 6 and below. It now has an issue when being called in IIS 7 and later versions. It displays an error message in the browser: “HTTP 502.2 - Bad Gateway”.

SOLUTION:

Here are the links that shows how to fix the problem:

-  http://www.techques.com/question/2-130423/Run-CGI-in-IIS-7-to-work-with-GET-without-Requiring-POST-Request

-  http://qc.embarcadero.com/wc/qcmain.aspx?d=50900

STEPS ON FIXING THE DELPHI CODE:

1.  Run Delphi 7, and open the “CGIStub” project. It is located in: C:\Program Files\Borland\Delphi7\Source\Internet\CGIStub.dpr

2.  Open the unit “CGIAPP”.

3.  Go to the “procedure TCGIApplication.Run” function and find the code: “Reset(Input);”.

4.  Change that code to this:

{$i-} {!!IIS7}

Reset(Input);

if IOResult >0 then ;

{$i+}

5.  Open the unit “CGIHTTP” and locate the function “TCGIRequest.ReadClient”.

6.  Change its code to: Result := FileRead(GetStdHandle(STD_INPUT_HANDLE), Buffer, Count);

7.  Compile the project and make sure there are no errors in compiling.

8.  Close the project. If you have already installed the Crystal Reports 9 Package, proceed to step # 15.

9.  Open the Crystal Reports 9 VCL Package in Delphi 7. The package file name can be dcl7cr9.dpk (for v.9), dcl7cr10.dpk (for v.10) and so on.

10.  Compile the package and a bpl file is generated. It may be found in C:\Program Files\Borland\Delphi7\Projects\Bpl directory.

11.  You are now ready to install the package in Delphi. Go to Component->Install Packages and click Add.

12.  Find the BPL file in Step 10 and click Open and then OK.

13.  The Crystal Reports 9 VCL Package has been installed.

14.  To manually add the crystal reports library, go to Tools->Environment Options. Go to the Library tab and edit the “Library Path”. Find the Crystal Reports Library path and click Add and OK. Please see image below:

15.  Open the “service” project and locate the text: “CGIAPP”.

16.  Edit that code by adding the full file path of the .pas file. Sample code is:

CGIApp in 'c:\program files\borland\delphi7\source\internet\cgiapp.pas',

17.  Now compile the project and make sure no errors are found.

18.  Locate the EXE program and replace the old service.exe and test the report generation.

19.  Repeat this steps for the serviceD.exe and serviceDDO.exe programs

20.  The “Bad Gateway” error should now be gone and the reports will generate properly.

FIXING THE INTERNAL SERVER ERROR 500 / ACCESS VIOLATION IN MODULE ‘ntdll.dll’

INTRODUCTION:

It displays an error message in the browser: “Server Error 500
Exception: EAccessViolation
Message: Access violation at address 77F4831D in module 'ntdll.dll'.”

SOLUTION:

Here is the link to the solution: https://www.devexpress.com/Support/Center/Question/Details/DQ10214

STEPS ON FIXING THE DELPHI CODE:

1.  Find the file SysUtils.pas at C:\Program Files\Borland\Delphi7\Source\Rtl\Sys.

2.  Copy and paste that file in the directory of your project.

3.  Open the file and replace the GetEnvironmentVariable function
with the following:

function GetEnvironmentVariable(const Name: string): string;
var
Len: integer;
W : String;
begin
Result := '';
SetLength(W,1);
Len := GetEnvironmentVariable(PChar(Name), PChar(W), 1);
if Len > 0 then
begin
SetLength(Result, Len - 1);
GetEnvironmentVariable(PChar(Name), PChar(Result), Len);
end;
end;

4.  Save and Recompile your project.

5.  The error should be gone now and the application executes normally.