on 08-22-2014 11:43 PM
I am working on an ASP.Net website to display a Crystal Report in a CrystalReportViewer on a ASP.Net page.
I am using Visual Studio 2013 and Crystal Reports 2011 for Sage.
I have Crystal Reports for Visual Studio version 13.0.2000.0 installed.
Trying run the Website on a Win 7 Pro in the local IIS.
On the Test1.aspx page, there are 2 DropDownList boxes for the user to filter the data for the report. When the user clicks on Run Report button, it does the following:
1. Connect to the Oracle database.
2. Run a query using a SELECT statement based on what the user selected in the DropDownList boxes.
3. Fill a dataset with the results of the query.
4. Set the CrystalReportViewer to the dataset.
CrystalReportViewer is not even shown on the web page.
I know the dataset is getting data because I can display it in a label.
What do I need to do to get this to work?
Test1.aspx ------
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test1.aspx.vb" Inherits="Test1" %>
<%@ Register assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
Plex H Shipment YM SUM Report<br />
<br />
Year:
<asp:DropDownList ID="ddlYear" runat="server">
</asp:DropDownList>
<br />
Month:
<asp:DropDownList ID="ddlMonth" runat="server">
<asp:ListItem Selected="True">ALL</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>11</asp:ListItem>
<asp:ListItem>12</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Run Report" />
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<asp:Label ID="Label2" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="Label3" runat="server"></asp:Label>
<br />
<br />
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" GroupTreeImagesFolderUrl="" Height="962px" ReportSourceID="CrystalReportSource1" ToolbarImagesFolderUrl="" ToolPanelWidth="200px" Width="1344px" EnableDatabaseLogonPrompt="False" EnableParameterPrompt="False" ToolPanelView="None" />
<CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
<Report FileName="PlexHShipmentYMSumReport_2.rpt">
</Report>
</CR:CrystalReportSource>
</div>
</form>
</body>
</html>
------------------------------------------------------------------------------------------------
Test1.aspx.vb -----
Imports CrystalDecisions.CrystalReports.Engine
Partial Class Test1
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim strCurYear As String
Dim intYear As String
'Get current Year.
strCurYear = Format(Now, "yyyy")
If ddlYear.Items.Count = 0 Then
'Add Items to Year Drop Down List.
ddlYear.Items.Add("ALL")
ddlYear.Items.Add(strCurYear)
intYear = Val(strCurYear) - 1
Do While intYear >= 2012
ddlYear.Items.Add(Trim(Str(intYear)))
intYear = intYear - 1
Loop
End If
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim sql As String
Dim strProcedure As String
Dim strYear As String, strMonth As String
Dim strErrorMsg As String
strProcedure = "btnRunReport_Click"
Try
sql = ""
strYear = ddlYear.Text
strMonth = ddlMonth.Text
sql = "SELECT SHIP_YEAR, SHIP_MONTH, SHIP_TO_BUILDING_CODE, TRUCK_CNT, INTERPLANT_SHIPPER_NO_CNT, " & _
"TOTAL_ITEM_CNT, GTOT_NET_WEIGHT, GTOT_GROSS_WEIGHT, ENTRY_DATE, REVISE_DATE " & _
"FROM VIEW_PLEX_H_SHIPMENT_YM_SUM "
If strYear = "ALL" And strMonth <> "ALL" Then
sql = sql & "WHERE SHIP_MONTH = '" & strMonth & "' "
ElseIf strYear <> "ALL" And strMonth = "ALL" Then
sql = sql & "WHERE SHIP_YEAR = '" & strYear & "' "
ElseIf strYear <> "ALL" And strMonth <> "ALL" Then
sql = sql & "WHERE SHIP_YEAR = '" & strYear & "' AND SHIP_MONTH = '" & strMonth & "' "
End If
sql = sql & "ORDER BY SHIP_YEAR ASC, SHIP_MONTH ASC"
Label1.Text = "SQL Statement is:"
Label2.Text = sql
Call CreateReport2(sql)
ExitReport:
Catch ex As Exception
'strErrorMsg = "Date/Time: " & Format(Now, "MM/dd/yyyy HH:mm:ss") & vbCrLf & _
' "Procedure: " & strProcedure & vbCrLf & _
' "Application: " & strAppName & vbCrLf & _
' "Error Message: " & ex.Message & vbCrLf & vbCrLf
'My.Computer.FileSystem.WriteAllText(strCurPath + "\" + strErrorLogFile, strErrorMsg, True)
End Try
End Sub
Protected Sub CreateReport(ByVal strSql As String)
End Sub
Protected Sub CreateReport2(ByVal strSQL As String)
Dim OrConn As Oracle.ManagedDataAccess.Client.OracleConnection
Dim OrCmd As Oracle.ManagedDataAccess.Client.OracleCommand
Dim OrDa As Oracle.ManagedDataAccess.Client.OracleDataAdapter
Dim OrCB As Oracle.ManagedDataAccess.Client.OracleCommandBuilder
Dim Rpt1 As ReportDocument
OrConn = New Oracle.ManagedDataAccess.Client.OracleConnection()
If IsNothing(Rpt1) Then
Rpt1 = New ReportDocument
End If
If OrConn.State <> Data.ConnectionState.Open Then
'Connection string using ODBC
'OrConn.ConnectionString = "DATA SOURCE=GTRANS01;PERSIST SECURITY INFO=True;USER ID=GADMIN;PASSWORD=GADMINPASS;"
'Connection string without using ODBC
OrConn.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=999.8.7.65)(PORT=999)))(CONNECT_DATA=(SERVICE_NAME=Z99)));User Id=user;Password=password;"
OrConn.Open()
End If
OrCmd = New Oracle.ManagedDataAccess.Client.OracleCommand(strSQL, OrConn)
OrCmd.CommandType = Data.CommandType.Text
OrDa = New Oracle.ManagedDataAccess.Client.OracleDataAdapter(OrCmd)
OrCB = New Oracle.ManagedDataAccess.Client.OracleCommandBuilder(OrDa)
Dim dsData As New Dataset1()
dsData.DataSetName = "PlexHShipmentYMSumData"
OrDa.Fill(dsData)
Label3.Text = "Dataset has " & dsData.Tables(0).Rows.Count & " records."
Rpt1.Load(Server.MapPath("PlexHShipmentYWSumReport_2.rpt"))
Rpt1.SetDatabaseLogon("user", "password")
Rpt1.SetDataSource(dsData.Tables(0))
CrystalReportViewer1.ReportSource = Rpt1
End Sub
End Class
Have a look at this:
See what KBAs, docs, etc, comes up when you enter the search term "crystal blank viewer' (and variations there off) in the search box - top right corner.
- Ludek
Senior Support Engineer AGS Product Support, Global Support Center Canada
Follow us on Twitter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I saw that earlier before I posted. I have tried it and it does not work.
I have tried with and without tilde (~) in the following:
<businessObjects>
<crystalReports>
<rptBuildProvider>
<add embedRptInResource="true"/>
</rptBuildProvider>
<crystalReportViewer>
<add key="ResourceUri" value="~/crystalreportviewers13"/>
</crystalReportViewer>
</crystalReports>
</businessObjects>
Currently, I have AutoDataBind property set to False for the CrystalReportViewer.
When I have it set to True, the ASP.Net page shows "Database logon failed" where the CrystalReportViewer is.
What should all the properties for the CrystalReportViewer be set to?
There is no Global.asax file.
Here is what my web.config looks like now:
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<sectionGroup name="businessObjects">
<sectionGroup name="crystalReports">
<section name="rptBuildProvider" type="CrystalDecisions.Shared.RptBuildProviderHandler, CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, Custom=null"/>
<section name="crystalReportViewer" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings>
<add key="CrystalImageCleaner-AutoStart" value="true"/>
<add key="CrystalImageCleaner-Sleep" value="60000"/>
<add key="CrystalImageCleaner-Age" value="120000"/>
</appSettings>
<connectionStrings>
<add name="OracleConnectionString" connectionString="Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=888.1.9.99)(PORT=90)))(CONNECT_DATA=(SERVICE_NAME=Z99)));User Id=user;Password=password;" providerName="Oracle.ManagedDataAccess.Client"/>
</connectionStrings>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5">
<assemblies>
<add assembly="CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.ReportSource, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
<add assembly="Oracle.DataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89B483F429C47342"/>
<add assembly="Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89B483F429C47342"/>
</assemblies>
<buildProviders>
<add extension=".rpt" type="CrystalDecisions.Web.Compilation.RptBuildProvider, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
</buildProviders>
</compilation>
<httpRuntime targetFramework="4.5"/>
<httpHandlers>
<add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
</httpHandlers>
</system.web>
<businessObjects>
<crystalReports>
<rptBuildProvider>
<add embedRptInResource="true"/>
</rptBuildProvider>
<crystalReportViewer>
<add key="ResourceUri" value="~/crystalreportviewers13"/>
</crystalReportViewer>
</crystalReports>
</businessObjects>
<system.webServer>
<handlers>
<add name="CrystalImageHandler.aspx_GET" verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" preCondition="integratedMode"/>
</handlers>
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
</configuration>
Any suggestions? What needs to be corrected?
What service pack for Crystal Reports for Visual Studio are you using?
What happens if you run any saved data report (you can try the attached - unzip, rename to .rpt) in a new one line web app:
New app.
Add the CR viewer
One line of code: CrystalReportViewer1.ReportSource = <path to the report"
- Ludek
How can I tell what Service Pack I using for Crystal Reports for Visual Studio?
In Visual Studio, it shows it as version 13.2000.0 when I look at the Extensions tab in References for the web site.
I have created a new web site, added a button, added the CR Viewer, add the .RPT file, and added the following code to the Button click:
CrystalReportViewer1.ReportSource = "~/Formulas.rpt"
I can see the report when I click on the button.
But I need to be able to filter the data using a dataset.
Re. How can I tell what Service Pack
Easy way:
Look at the version of the crpe32.dll here:
C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86
The version will be something like 13.0.xx.yyy. It's the xx that tells you the SP. So 13.0.10.yy would be SP 10.
The other way:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.Reflection
Imports System.Runtime.InteropServices
Public Class Form1
Private Sub CrystalReportViewer1_Load(sender As Object, e As EventArgs) Handles CrystalReportViewer1.Load
For Each MyVerison As Assembly In AppDomain.CurrentDomain.GetAssemblies()
If MyVerison.FullName.Substring(0, 38) = "CrystalDecisions.CrystalReports.Engine" Then
Dim fileVersionInfo As System.Diagnostics.FileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(MyVerison.Location)
MessageBox.Show(fileVersionInfo.FileVersion.ToString())
Return
End If
Re. dataset. The data source should not matter in rendering of the viewer. Data may be - e.g.; say data is missing, or the report prompts for db logon. But the viewer should come up irrespective. So, compare the test app to your app. What is the diff in terms of the viewer config?
- Ludek
I am using Service Pack 9 of Crystal Reports for Visual Studio.
The only difference with the CrystalReportViewer between the test app and my app was that my app has CrystalReportViewer configured to point to the ReportSource object which in turn points to the .rpt file. The test app you have me create does not have the ReportSource object and just has the following line of code to view the Formulas.rpt:
CrystalReportViewer1.ReportSource = "~/Formulas.rpt"
In the test app, I have been putting in code from my app to narrow down when the CrystalReportViewer will not be shown. Here is the code:
Dim Rpt1 As ReportDocument
Rpt1 = New ReportDocument
'Rpt1.Load(Server.MapPath("~/PlexHShipmentYWSumReport_2.rpt"))
'Rpt1.SetDatabaseLogon("user", "password", "888.9.1.77", "GTRANS01")
'Rpt1.SetDataSource(dsData)
'CrystalReportViewer1.ReportSource = "~/PlexHShipmentYMSumReport_2.rpt"
CrystalReportViewer1.ReportSource = "~/Formulas.rpt"
A single quote is used to comment out the Rpt1.Load, Rpt1.SetDatabaseLogon, Rpt1.SetDataSource, and the first CrystalReportViewer1.ReportSource lines of code.
With those lines of code commented out, the CR Viewer shows the Formulas.rpt report file.
If I uncomment out the CR Viewer for PlexHShipmentYMSumReport_2.rpt and comment out the CR Viewer for Formulas.rpt then the CR Viewer is displayed with the following:
Error
Database Logon failed
But no matter what .rpt is used with the CR Viewer, when Rpt1.Load or Rpt1.SetDataSource is uncommented out then the CR Viewer is NOT shown. I do not understand why that happens. I need help to fix that.
With the test app, the web.config was not changed at all.
In my app, when I comment out those Rpt1 lines then the CR Viewer is displayed with an error or shows the report with the saved data.
Please help.
Well, looking at the code, you are asking the report to logon to the database and then you are telling it to consume a dataset (I realize it's commented out so maybe you were just trying it all). In any case, what is it you want the report to use; direct database connection, or a dataset? If a dataset, your code would be:
Dim crReportDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument
crReportDocument.Load(Server.MapPath("~/PlexHShipmentYWSumReport_2.rpt"))
'create your dataset
crReportDocument.SetDataSource(dataSet)
CrystalReportViewer1.ReportSource = crReportDocument
If you are trying to do a direct connection to a database, then the code gets a bit more complex. See the sample app "vbnet_win_dbengine.zip" here: Crystal Reports for .NET SDK Samples - Business Intelligence (BusinessObjects) - SCN Wiki
Developer Help files are here:
SAP Crystal Reports .NET SDK Developer Guide
SAP Crystal Reports .NET API Guide
And this is pretty well a must resource for any developer:
Crystal Reports for Visual Studio 2005 Walkthroughs (applies to all versions of .NET and CR).
- Ludek
Thanks for your response!
I would like the report to use a dataset not connect directly to the database.
I have tried what you suggested for the dataset and still does not work.
There is something else I have found that may be related to why the CR Viewer is not displayed.
In my code, the ReportDocument method Load is called before my Label3 is populated with text and then Label3 and the CR Viewer is not displayed. If the ReportDocument method Load is called after Label3 is populated then Label3 is displayed. This issue occurs with any ReportDocument method that is called.
If no ReportDocument method is called then all objects are displayed on the ASP.Net page.
Any ideas?
Not much of an idea, except the obvious; the viewer is not being called in the cases where it does not work. Stepping through the code should show you what is happening. Again, I go back to the simplify paradigm:
The code I suggested should be ok as it is pretty simple. Now build on that(?).
- Ludek
Thanks for your response!
I have been going through the Crystal Reports for Visual Studio 2005 Walkthroughs document you gave a link for.
Right now I have been going through "Persisting the ReportDocument Object Model Using Session" section to see if it would give any insight to resolving my issue. In doing that, hierarchicalGroupingReport shows as not declared when coding it in Visual Studio 2013. What do I need to declare that?
User | Count |
---|---|
84 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.