?
Solved

Crystal Reports 2008 .NET Viewer prompts for db password on page refresh

Posted on 2009-04-16
3
Medium Priority
?
664 Views
Last Modified: 2012-05-06
As an alternative to the Crystal Reports ActiveX viewer on IIS, we ended up using a solution which was a mixture of this EE post http://www.experts-exchange.com/Database/Reporting_/Crystal_Reports/Q_22689905.html and the post by Hilfy here http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=589

Basically, we store the cr datasource username, password, and server in web.config - and on page load the report name is in the query string of the URL.  Works PERFECTLY and we are very happy with it.

However, when we attempt to refresh the page it prompts for the database password again.
I've been scouring for several hours to figure out why this happens... any idea?  I tried moving to Page_Init instead of Page_Load, same issue.  I was wondering if there was something specific I was missing.
0
Comment
Question by:Landho
3 Comments
 
LVL 12

Expert Comment

by:topdog770
ID: 24173035
When the refresh occurs, re-set the logon information.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24177079
Can you show us the code you are using in page load?
0
 
LVL 1

Accepted Solution

by:
Landho earned 0 total points
ID: 24499565
code is below... some of the config is stored in web.config, could easily be changed so you pass it on page load or grab it from someplace else.
using System;
using System.Data;
using System.Collections.Specialized;
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 System.IO;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Web;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;
using System.Diagnostics;
 
public partial class _Default : System.Web.UI.Page 
{
    protected string reportPath = ConfigurationManager.AppSettings["Rptpath"].ToString();
    protected string dbName = ConfigurationManager.AppSettings["dbName"].ToString();
    protected string dbUser = ConfigurationManager.AppSettings["dbUser"].ToString();
    protected string dbPass = ConfigurationManager.AppSettings["dbPass"].ToString();
    protected string serverName = ConfigurationManager.AppSettings["serverName"].ToString();
 
    protected void Page_Load(object sender, EventArgs e)
    {
        CrystalDecisions.CrystalReports.Engine.ReportDocument crReport = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
        string reportName = Request.QueryString["ReportName"];
        string qServer = serverName;
        string rptPath = reportPath;
        crReport.Load(rptPath + reportName);
 
        ParameterDiscreteValue discreteVal = new ParameterDiscreteValue(); 
        ParameterRangeValue rangeVal = new ParameterRangeValue(); 
        ParameterValues curvalues = new ParameterValues(); 
 
        foreach (ParameterFieldDefinition parafld in crReport.DataDefinition.ParameterFields) 
        { 
            if (parafld.DiscreteOrRangeKind.ToString() == "DiscreteValue") 
            { 
                discreteVal.Value = Request.QueryString[parafld.ParameterFieldName]; 
            if (discreteVal.Value != null) 
            { curvalues.Add(discreteVal); parafld.ApplyCurrentValues(curvalues); 
            } 
            } 
        }
 
 
        CrystalDecisions.Shared.ConnectionInfo connectionInfo = new CrystalDecisions.Shared.ConnectionInfo();
        connectionInfo.ServerName = serverName;
        connectionInfo.UserID = dbUser;
        connectionInfo.Password = dbPass;
        // set report connection for main report    
        SetDBLogonForReport(connectionInfo, crReport, qServer);    
        // set report connection for any subreports    
        SetDBLogonForSubreports(connectionInfo, crReport, qServer);    
        // set group tree function off             
        //CrystalReportViewer.DisplayGroupTree = false;    
        // view report
        Viewer.ReportSource = crReport;
    }
 
    private void SetDBLogonForReport(CrystalDecisions.Shared.ConnectionInfo connectionInfo, ReportDocument reportDocument, string qServer)
    {
        Tables tables = reportDocument.Database.Tables; 
        foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables) 
        { TableLogOnInfo tableLogonInfo = table.LogOnInfo; 
            tableLogonInfo.ConnectionInfo = connectionInfo; 
            table.ApplyLogOnInfo(tableLogonInfo); 
        }
    }
    private void SetDBLogonForSubreports(CrystalDecisions.Shared.ConnectionInfo connectionInfo, ReportDocument reportDocument, string qServer)
    {
        Sections sections = reportDocument.ReportDefinition.Sections; 
        foreach (Section section in sections) 
        { ReportObjects reportObjects = section.ReportObjects; 
            foreach (ReportObject reportObject in reportObjects) 
            { 
                if (reportObject.Kind == ReportObjectKind.SubreportObject) 
                { 
                    SubreportObject subreportObject = (SubreportObject)reportObject; 
                    ReportDocument subReportDocument = subreportObject.OpenSubreport(subreportObject.SubreportName); 
                    SetDBLogonForReport(connectionInfo, subReportDocument, qServer); 
                } 
            } 
        }
    }
}
 
 
____________________________________________________________
and the aspx page
-------------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register assembly="CrystalDecisions.Web, Version=12.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" namespace="CrystalDecisions.Web" tagprefix="CR" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Report View</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <CR:CrystalReportViewer ID="Viewer" runat="server" AutoDataBind="True"
            ReportSourceID="CrystalReportSource1"  />
        <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
        </CR:CrystalReportSource>
    </div>
    </form>
</body>
</html>

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question