After reading the following article you will have a better understanding of how you can use AR2 on the web.
The ASP application performs a response.binarywrite to display the report
Overview of the ReportFactory.Dll project attached: The .dll will load an ActiveReports RPX file. Run the report based on this RPX file, export the report to a PDF byte array, and return the PDF byte array to the calling application.
Benefits of using AR2 over AR1 on the web ActiveReports version 1 did not have the RPX file format. Report designers had to be embedded into the actual .dll itself. Placing a visual component inside of an ActiveX dll like this disables the 'unattended execution' and 'retained in memory' settings in the .dll.
Microsoft now recommends that these setting are always checked. Using RPX files allows users to load reports into their .dll objects dynamically at run time. No visual components need be placed inside of the .dll object. This allows users to have check the 'unattended execution' and 'retained in memory' options of the .dll project, and also provides a smaller .dll file size since no ActiveX designers are being compiled into the .dll.
More benefits Since you can use RPX files with AR2 instead of having to place your reports inside of the .dll there is no longer a need for users to have to recompile their .dll if they need to make a change to a report. Users can simply update the .rpx file on the web server to update the report. No .dll recompilation is needed.
Sample #1: WebProject.
Requirements
Internet Information Server
What does this sample contain?
This sample contains 2 subfolders:
bin -contains data dynamics runtime, data dynamics
PDF export filter, and a DLL created in Visual Basic (ActiveX in process DLL).
RPXFiles –contains a pre-saved ActiveReport in RPX format
(RPX is Data Dynamics XML format which is named .RPX instead of .XML so that we
can differentiate our XML files from everyone else.)
Also included in this folder are the following files:
default.htm - the default html page shown when you access this site
ByteArray.asp- default.htm calls this ASP file.
This ASP file calls a COM object to generate an ActiveReport and export report’s
ByteArray to the ASP to be redirected to the screen.
What does this sample do?
This sample is a web based sample meant to be run on a test web server.
The sample demos activereports 2.0 on the web. It also shows users how to call
a DLL from an ASP page and return the report’s ByteArray so the ByteArray can be
redirected to the screen. In this demo it is the PDF bytearray the is being
redirect. The sample also demos streaming reports directly to the client
browser using the exportstream method of the PDF export filters.
Installation
To setup this sample please perform the following steps:
1)Right click on the WebProject folder and go to properties.
2)Click on the web sharing tab and share the folder as WebProject.
3)This folder will now be available under Internet Information Server.
as a virtual directory
4)Inside of the WebProject folder is a subfolder called bin.
Inside of the bin folder are dlls.
Register these dlls with regsvr32 from the start menu's run prompt
i.e. regsvr32 c:\documents and settings\admin\desktop\ddwebproject\example.dll
Note: You only need to register ReportFactory.dll if you already have ActiveReports 2.0 installed
5)Open Internet Information Server and click on the new WebProject folder.
6)There is a subfolder in this folder called "bin"
7)Right click on this folder and set the execute permissions from
"Scripts only" to "Scripts and Executables
8)You are now ready to see a running sample of ActiveReports 2.0 on the web.
9)Open Internet explorer and browse to http://localhost/WebProject/
10)If everything has been setup correctly you should see a default html page
with an option to view a PDF streamed report.
Sample #2: ReportFactory.
Requirements
Visual Basic 6
ActiveReports 2 Eval or Full edition
Microsoft Access
What does this sample contain?
This sample consists of a standard visual basic VBG project. The VBG project
is made up of one exe and one COM dll.
What does this sample do?
This sample is meant to be run in the VB IDE. The sample contains the COM object
that is used in the first sample entitled WebProject. Using this sample you can
view all of the code inside of the ReportFactory.dll. The exe was included simply for the
purpose of testing the COM object. The EXE will allow you to save your dsr to an
RPXfile and calls the ReportFactory.dll to export reports to the PDF ByteArray. Using this
sample you will be able to completely familiarize yourself with all of the code
needed to export an ActiveReport to a ByteArray and you can add any additional
code to the ReportFactory.dll that you like.
I Can't Generate Reports From ASP! (troubleshooting section)
Are you receiving an error message trying to generate reports?
Is IIS hanging?
Is your application hanging?
Can you call your dll from the VB IDE or a test EXE but not from IIS?
By the time you read the next article you will be an expert at troubleshooting your web-based reports! The entire purpose of this article is to help you troubleshoot and figure out any problem you may be having with generating ActiveReports from ASP. I will start with the most common problems first and work through to more uncommon issues.
Any time you have ActiveReports inside of a COM object (ActiveX dll or ActiveX exe) you must have the following lines of code inside each of your ActiveReports in order for them to function correctly when called from ASP. You will see a code example first, then I will explain the reasoning behind the code and why it is used.
ActiveReport_Initialize()
Me.Printer.DeviceName = ""
End sub
Private Sub ActiveReport_Error(ByVal Number As Integer, ByVal Description As DDActiveReports.IReturnString,ByVal Source As String, ByVal CancelDisplay As DDActiveReports.IReturnBool) )
App.LogEvent "Error Event hit " & number & " " & description
CancelDisplay=true
End sub
Leaving out the code in the two ActiveReports Events above is the largest cause for errors with ActiveReports wrapped in COM objects.
The first line of code that you see above
Me.Printer.DeviceName=""
tells ActiveReports not to worry about locating a default printer. It tells ActiveReports to just go ahead and use the built-in virtual printer driver instead. This is very important for two reasons. First, most web servers don't have a printer installed. If this line of code is missing, and ActiveReports cannot find a default printer the report will not run. Secondly, even when there is a default printer installed, COM objects sometimes have difficulty finding the default printer or its settings when called from IIS. So get rid of headaches early by adding this line of code.
The next code segment demonstrated above is the correct way to lay out ActiveReports_Error event. Not having the code inside of the ActiveReports_Error event above is the most common reason applications "hang". If a message box attempts to display because of an error that fired inside of your ActiveX .dll it will hang your application, and sometimes the entire World Wide Web Service. ActiveX .dlls do not have a UI(User Interface) and cannot display message boxes that are produced from an error. This is the cause of the application "freezing" or "hanging". To prevent this place
CancelDisplay=True
inside of the ActiveReports Error event. This tells ActiveReports if any message box attempts to display cancel it. However, we still want to know the error occurred.
That is where the next line of code comes in:
App.LogEvent "Error Event hit " & number & " " & description.
App.logevent logs any string parameter you supply to the NT applications log on NT 4 and Windows 2000. It logs the specified string parameter to a file called VbEvents.log on a 95 or 98 machine. If the report does not run for some reason you can check the log file and see if an ActiveReports error fired.
All of the above information will help you resolve some of the most common errors experienced with web reporting using ActiveReports. If you have all of the above recommended code inside of your reports you know you are starting on the right foot. Below is a list of other errors that users experience with web reporting
More Errors and their possible causes (More troubleshooting Help)
1. ASP error: Server.createObject failed (when calling your ActiveX dll)
Possible Causes:
a. Your ActiveX .dll is not registered. Run regsvr32 on the .dll to be sure that it is.
b. Your ActiveX .dll is in a folder that I_Usr_machineName (the default IIS user, or whatever user you are using for your web site instead of I_Usr_MachineName) does not have permission to access.
2. My report dies on the ActiveReportName.run line inside of my function in my .dll class.
Possible Causes:
a. Whenever you receive an error on the ActiveReportName.run line you have a little troubleshooting to do. This line is responsible for firing every single event inside of ActiveReports. So you could have an error firing anywhere inside of the report. You need to try to narrow your error down to one line of code or at least one particular section of the report. The most effective troubleshooting tool to accomplish this is App.LogEvent . App.LogEvent will take any string parameter you supply to it and log it to the NT applications log (or vbEvents.log on a Win95 or Win98 machine). This form of troubleshooting will allow you to find out exactly how many events in your report are firing before the error occurs, and what the error number and description are when it does occur. It is recommended when troubleshooting an error like this you place App.logevents in the following events:
ActiveReports_ReportStart - Tells us ActiveReports is Starting okay.
ActiveReports_ReportEnd - Tells us ActiveReports is finishing okay.
ActiveReports_NoData - Tells us whether our recordset is empty.
ActiveReports_error - tells us that an ActiveReports error has occurred
Here is an Example of how to use App.LogEvent:
ActiveReport_ReportStart()
On Error goto errorhandler
App.logevent "Report Started Successfully"
[[any code you may have goes here]]
exit sub
errorhandler:
App.LogEvent "An Error Occurred in ReportStart " & err.number & " " & err.description
End Sub
As you can see this will allow us to read our log after our run and see whether or not our report did indeed make it to this point and if an error occurred or not.
3. My ActiveX .dll works just fine when I call it from the VB IDE or from a test Visual Basic Executable but it doesn't when called from IIS?
Possible Causes:
a. In situations like this you have to think about the difference between calling a .dll from an EXE versus calling a .dll from IIS. This means "PERMISSIONS". Make sure I_Usr_MachineName (or whatever user you have setup for your website instead of I_Usr_machineName) has permissions to access your ActiveX dll, actrpt.dll and any database you are connecting to. You can temporarily give I_Usr_MachineName(or again whatever user you are using for your website instead of I_Usr_MachineName) Administrative privileges to verify permissions as the problem.