Crystal Solutions for printing reports in a Web environment

Source: Internet
Author: User
Tags define dsn error handling connect odbc access database
web| Printing | Print Report | solve <%@ language= "VBSCRIPT"%>
<%
' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
' Generate reports directly from the ADO recordset
' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
'
Concept
'
' This application is designed to demonstrate how to generate reports from the ADO recordset. We first set up the ADO connection and
' Recordset object, and then generate a recordset from the database with an SQL statement. And then we build a crystal
' Reports object and point this object to the ADO recordset. Finally we will crystal Reports
' Smart Viewer is sent to the client to display this report.

' First step: Create the ADO Connection and Recordset

' An ADO database connection is accessed via an existing ODBC data source (DSN) from an application like ASP
' The connection of the data. To achieve the purpose of this example, we will use a Xtreme named "Sample Data"
' Connect to Access database Xtreme.mdb System DSN

' Create an ADO database connection:

Set oconn = Server.CreateObject ("ADODB. Connection ")

' Here we have an ADO connection called "oconn," which we'll connect to the above DSN with this ADO Connection object

' Use ADO connection must first open it:

oConn.Open ("Xtreme Sample Database")

' Here opens our ODBC data source, which points to an Access database Xtreme.mdb

' Now we have to create a Recordset object:

Set session ("ORs") = Server.CreateObject ("ADODB"). Recordset ")

' On top we set up a session ("ORs"). A Recordset object is stored in this session
' will contain the data returned with the SQL statement

' Define and generate a recordset:

Session ("ORs"). ActiveConnection = oconn
' Define the Connection object that this recordset will use

Session ("ORs"). Open SELECT [Product ID], [Product Name] from product

' Use SQL statements to remove two fields from the ' Product ' table in the Xtreme.mdb library

'===================================================================================
' Establish crystal Reports object
'===================================================================================
' You may notice that the Crystal reports object is set to session, because the requirement is called
' rptserver.asp ' ASP processing, in order for rptserver.asp to be able to easily access crystal,
' We set these objects to session. So that any ASP page runs in this session, you can access these objects directly

ReportName = "Adorecordset.rpt"

' Here, create a string variable, point to the Crystal (. rpt file), and then use this code
' Replace your crystal with the file name.

' Create a Application object
If not IsObject (session ("Oapp")) Then
Set session ("oapp") = Server.CreateObject ("Crystalruntime.application")
End If

' This ' if/end if ' structure is used to create Crystal Reports application objects per session only once O
' Set up Application Object-session ("Oapp"), will crystal the design of the bill Component
' Automation server (Craxdrt.dll) is loaded into memory.
'
We set up the session variables to use them in the ASP session. This will reduce the Craxdrt.dll
' Load and unload system overhead. Once a Application object is established in a session, we don't have to
' Rebuild the object to run more reports.

' Establish the object of the study
'
' The OpenReport method of the application was established

Path = Request.ServerVariables ("path_translated")
while (right (path, 1) <> "\" and Len (path) <> 0)
Ilen = Len (Path)-1
Path = Left (path, Ilen)
Wend
Response. Write Path
' This ' while/wend ' loop is used to convert the current file from the virtual path (Eg:http://domain/dir) to Crystal
' The physical path of the ' file ' (eg:c:\)

' Open the bill (remove any previous objects first)

If IsObject (Session ("Orpt")) Then
Set session ("orpt") = Nothing
End If

On Error Resume Next

Set session ("ORPT") = Session ("Oapp"). OpenReport (Path & ReportName, 1)
' Here, the physical path of the crystal file is computed and opened using the ' path ' and ' ReportName ' variables.

If err.number <> 0 Then
Response.Write "Error occurred creating": "& Err.Description
Set session ("orpt") = Nothing
Set session ("oapp") = Nothing
Session.Abandon
Response.End
End If

' This on Erro resume Next block checks for any errors that occur when you create a show object, and we are explicitly capturing any
' Error if the view exceeds the maximum number of concurrent users specified in the license agreement.

' Note that we are not only setting up a one-time object. This is because of the ASP session you can handle more than one report
' Rptserver.asp will only deal with a "session" ("Orpt") of the A. So if you want to work with multiple reports
' Then, a new session ("Orpt") object will be established.

Session ("Orpt"). Moreprintengineerrormessages = False
Session ("Orpt"). enableparameterprompting = False

' Error reporting mechanisms are not allowed here, including Crystal Report Design Component Automation server (Craxdrt.dll)
' Built-in error reporting, which is because of two reasons:
' 1. The print engine is executed on the Web server, so any error message will be displayed on the server, if an error is reported on the server side,
' The print engine will stop functioning and your application will be ' suspended '
' 2. Rptserver.asp already has some error handling logic inside, which can catch any non-fatal errors and appear on the client.
'
' * * IMPORTANT * Even if we prohibit error handling for server-side engines, fatal errors are captured on the Web server service side and
' Displays the Error prompt dialog box. So we suggest that you set up the world Wide Web Publishing Service (IIS service)
' Allow Service to interact with Desktop ' option. So if your ASP application dies, you will be able to see the error message.

'========================================================================



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.