Click here to Skip to main content
15,077,641 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a web form that has crystal report viewer on it. It works on the test environment. When it is on the server it won't display. Error shows Database Logon Failed. I created the report with Crystal Report 2013. I then imported it into the project and add it to the report viewer. Here is the code behind the report viewer that loads the report and logs into the database.

using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using CrystalDecisions.Web;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Windows.Forms;
using CrystalDecisions.ReportSource;
using CrystalDecisions.ReportAppServer;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Xml.Linq;
using System.Web.SessionState;

namespace SACSCOCLogin1._1
    public partial class ReportFormD : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
            TextBoxINST_ID.Text = Session["inst_id"].ToString();
            CrystalReportViewer1.Visible = true;

            ReportDocument CrystalReport = new ReportDocument();
            ParameterField paramField = new ParameterField();
            ParameterFields paramFields = new ParameterFields();
            ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();

            paramField.Name = "inst_id";
            paramDiscreteValue = new ParameterDiscreteValue();
            paramDiscreteValue.Value = TextBoxINST_ID.Text;
            CrystalReportViewer1.ParameterFieldInfo = paramFields;

            string sessiontype = TextBoxINST_ID.Text;
            CrystalReport.SetParameterValue("inst_id", TextBoxINST_ID.Text);

            string sessionid = TextBoxINST_ID.Text;
            CrystalReport.SetParameterValue("inst_id", TextBoxINST_ID.Text);
            CrystalReport.SetDatabaseLogon("Admin", "password", "SQL Server", "Hot");
            CrystalReportViewer1.ReportSource = CrystalReport;

Is there something wrong with my code? What did I do wrong?

Here is my Web.config file:

      <add key="CrystalImageCleaner-AutoStart" value="true" />
      <add key="CrystalImageCleaner-Sleep" value="60000" />
      <add key="CrystalImageCleaner-Age" value="120000" />
    <add key="resourceURI" value="~/aspnet_client/system_web/4_0_30319/crystalreportviewers13" />
    <add name="HotConnectionString" connectionString="Data Source=SQL Server;Initial Catalog=Hot;Integrated Security=True" providerName="System.Data.SqlClient"/>
      <add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>
      <add verb="GET" path="CrystalImageHandler.aspx" type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
    <compilation debug="true" targetFramework="4.0">
        <add assembly="Microsoft.ReportViewer.WebForms, Version=, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="Microsoft.ReportViewer.Common, Version=, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="Microsoft.Build.Framework, Version=, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="System.Management, Version=, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
        <add assembly="CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
        <add assembly="log4net, Version=, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
        <add assembly="CrystalDecisions.ReportSource, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
        <add assembly="CrystalDecisions.ReportAppServer.Controllers, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
        <add assembly="CrystalDecisions.ReportAppServer.DataDefModel, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
        <add assembly="CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
      <add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/></assemblies>
        <add extension=".rpt" type="CrystalDecisions.Web.Compilation.RptBuildProvider, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"/>
    <pages maintainScrollPositionOnPostBack="true"/>
    <customErrors mode="Off" defaultRedirect="Oops.aspx"/>
    <authentication mode="Forms">
      <forms loginUrl="/Login.aspx"/>
    <validation validateIntegratedModeConfiguration="false"/>
      <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
      <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"/>

Does all of the code look ok?
thatraja 16-Apr-14 6:00am
Are you able to connect the database from that page? Just write a simple code to retrieve a value(simple SELECT query) from database.
Computer Wiz99 16-Apr-14 6:05am
I am able to connect to t b en database in crystal report a b day view the data but when the report is called on the server it gives the error Database logon failed.
thatraja 16-Apr-14 6:08am
Did you verify the server web.config has right logon details?
Computer Wiz99 16-Apr-14 6:23am
Everything should be integrated. How do I do the logon in web.config?
thatraja 16-Apr-14 6:39am
I'm talking about web.config values. Is your server machine's web.config has right logon details?
You should not hard-code values like below
/* CrystalReport.SetDatabaseLogon("Admin", "password", "SQL Server", "Hot"); */
You should get values from web.config file.
Computer Wiz99 16-Apr-14 6:47am
Ok. I'm new to iis 8. How would I do that?
thatraja 16-Apr-14 7:01am
:confused: Can't you find web.config file from appropriate virtual directory? And check the file for logon details
Computer Wiz99 16-Apr-14 10:13am
That still didn't work. Is there a way for me to Integrated Security=True for the SetDatabaseLogon?
thatraja 16-Apr-14 10:29am
Yep, check updated answer below.
Computer Wiz99 16-Apr-14 10:35am
Ok. This is what I found out. On my Server 2003 I have SQL Server 2005 . When I open SQL Server Management Studio it asks for a Server Name and Authentication. I am using Windows Authentication for Authentication. Then I can see all of my databases. How can I get that to work for Crystal reports when it is deployed to the web server? Thing is that the web app can connect to the SQL server database but the CR can't. Can you show me an example code for what needs to be replaced in my code?
thatraja 16-Apr-14 10:45am
Did you check the 2nd & 3rd link from my answer.
You could find code for Integrated Security from 2nd link &
you could find code for sending blank logon details from 3rd link.
Recheck those links
Computer Wiz99 16-Apr-14 12:01pm
I have tried the links and this line: foreach (CrystalDecisions.Shared.IConnectionInfo connection in reportDocument.DataSourceConnections). I get error on this part: ReportDocument.DataSourceConnections. Error says: An object reference is required for the non-static field, method, or property 'CrystalDecisions.CrystalReports.Engine.ReportDocument.DataSourceConnections.get'. How can i fix this?

thatraja 17-Apr-14 3:15am
Include the code in your question

1 solution


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900