cancel
Showing results for 
Search instead for 
Did you mean: 

CrystalReportViewer

Former Member
0 Kudos

Post Author: tjlague

CA Forum: .NET

I need assistance with CrystalReportViewer functionality. I have a report that displays on initial page load but when any of the CrystalReportViewer buttons are clicked the report prompts the user to authenticate. I would like to eliminate the authentication prompt. Below is my code: /////////////////////////////////Sample.aspx.cs using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using CrystalDecisions.Shared;using CrystalDecisions.CrystalReports.Engine;using CrystalDecisions.Web;public partial class Sample : System.Web.UI.Page { private ReportDocument SampleReport; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ConfigureCrystalReports(); } } private void ConfigureCrystalReports() { ConnectionInfo connectionInfo = new ConnectionInfo(); connectionInfo.ServerName = "server"; connectionInfo.DatabaseName = "database"; connectionInfo.UserID = "user"; connectionInfo.Password = "password"; SampleReport = new ReportDocument(); string reportPath = Server.MapPath("Reports/Sample.rpt"); SampleReport .Load(reportPath); SetDBLogonForReport(connectionInfo, SampleReport); CrystalReportViewer1.ReportSource = SampleReport; } private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument) { Tables tables = reportDocument.Database.Tables; foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables) { TableLogOnInfo tableLogonInfo = table.LogOnInfo; tableLogonInfo.ConnectionInfo = connectionInfo; table.ApplyLogOnInfo(tableLogonInfo); } } } /////////////////////////////////Sample.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Sample.aspx.cs" Inherits="Sample" %><%@ Register TagPrefix="CR" Namespace="CrystalDecisions.Web" Assembly="CrystalDecisions.Web, Version=11.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Sample Report</title></head><body> <form id="form1" runat="server"> <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True" Height="1039px" ReportSourceID="CrystalReportSource1" Width="901px" HasCrystalLogo="False" HasViewList="False" HasRefreshButton="True" /> <CR:CrystalReportSource ID="CrystalReportSource1" runat="server"> <Report FileName="Reports\Sample.rpt"> </Report> </CR:CrystalReportSource> </form></body></html> Any assistance is appreciated. Code examples are preferred. Thanks!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Post Author: Argan

CA Forum: .NET

Try removing the postback check before doing the configurecrystal call.

The report is run for every page in a web app so it will fail when it makes the database call.

One thing to try instead is to put the report object into session and then for each postback set the crystal report viewer to the report in session. Then it should run off of the report stored in session instead of rehitting the database.

Answers (1)

Answers (1)

Former Member
0 Kudos

Post Author: SatishFiserv

CA Forum: .NET

I just moved from .Net 1.1 to .Net 2.0.

My reports do not work as they used to work.

This is the piece of code the used to work....

rpt.Load(reportSource + @"\AuditLog\" + reportConfig.ReportName);

//rpt.SetDataSource("fsp_AuditLogReport_Get;1");

addReportParameter(rpt, "@EntryDtFrom", reportConfig.fromDate.ToString("G"));

addReportParameter(rpt, "@EntryDtTo", reportConfig.toDate.ToString("G"));

if (reportConfig.UserID!=null && reportConfig.UserID!="")

addReportParameter(rpt, "@UserId", reportConfig.UserID);

addReportParameter(rpt, "@Application", (reportConfig.AppName==null || reportConfig.AppName=="") ? "%" : reportConfig.AppName);

if (reportConfig.EnvironmentName!=null && reportConfig.EnvironmentName!="")

addReportParameter(rpt, "@EnvironmentName", reportConfig.EnvironmentName);

if (reportConfig.SPName!=null && reportConfig.SPName!="")

addReportParameter(rpt, "@SnapInName", reportConfig.SPName);

addReportParameter(rpt, "@MessageName", (reportConfig.MessageName==null) ? "%" : reportConfig.MessageName);

#region set up database connection to Communicator database

ParseDBConnForKey(dbConComm, out serverName, out database, out userid, out password);

logonInfo = new TableLogOnInfo();

logonInfo.ConnectionInfo.ServerName = serverName;

logonInfo.ConnectionInfo.DatabaseName = database;

logonInfo.ConnectionInfo.UserID = userid;

logonInfo.ConnectionInfo.Password = password;

for (int n = 0; n < rpt.Database.Tables.Count; n++)

{

rpt.Database.Tables&#91;n&#93;.ApplyLogOnInfo(logonInfo);

rpt.Database.Tables&#91;n&#93;.Location = database + ".dbo."

+ rpt.Database.Tables&#91;n&#93;.Location.Substring(rpt.Database.Tables&#91;n&#93;.Location.LastIndexOf(".") + 1);

}

#endregion

//rpt.Refresh();

//rpt.VerifyDatabase();

// Export the report

rpt.ExportToDisk(ExportFormatType.PortableDocFormat, fullPath);

*****************

private void addReportParameter(ReportDocument rpt, string param, string val)

{

if (val != null && val != "")

{

ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

crParameterDiscreteValue.Value = val;

ParameterValues CrParaVals = rpt.DataDefinition.ParameterFields&#91;param&#93;.CurrentValues;

CrParaVals.Add(crParameterDiscreteValue);

rpt.DataDefinition.ParameterFields&#91;param&#93;.ApplyCurrentValues(CrParaVals);

}

}

*****************

now i get a ...

Exception Type Name = FormulaException Exception Number = Exception Message = This field name is not known.Error in File C:\DOCUME1\kondursx\LOCALS1\Temp\auditlog {D872CC24-4C12-4543-B75A-EEFDC3FECD38}.rpt:Error in formula <DateToConverted>. 'DateAdd ("h", DateDiff ("h", {fsp_serverLocalTime;1.SqlLocalTime}, CurrentDateTime), {?@EntryDtTo})'This field name is not known. Exception Trace = at CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e) at CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext) at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext) at CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToDisk(ExportFormatType formatType, String fileName) at Fiserv.CBS.Communicator.Tasks.ReportManagerTask.ReportGenerator.generateReport() in C:\Communicator\Base\7.2\Service Providers\Source Code\ReportManagerTask\ReportGenerator.cs:line 226 at Fiserv.CBS.Communicator.Tasks.ReportManagerTask.ReportManagerTask.OnRun(Guid msgGuid) in C:\Communicator\Base\7.2\Service Providers\Source Code\ReportManagerTask\ReportManagerTask.cs:line 126

The report uses 2 stored preedures. Am new to crystal so bear with me here.

Some the commented stuff in the code is what i have tried so far with not much luck. When i did the refreesh I saw that the Prameter values just dissappeared.

Thankx in advance for any help I can get.