Error Object reference not set to an instance of an object.(Urgent)

Analyst_SQL 3,576 Reputation points
2022-05-27T06:11:50.817+00:00

Crystal Report View is not working on server side ,

Error Object reference not set to an instance of an object.(Urgent)

But working on locally fine

code

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
using System.Configuration;  
using System.Data;  
using System.Data.SqlClient;  
using System.IO;  
using System.Globalization;  
using Microsoft.Reporting.WebForms;  
using CrystalDecisions.CrystalReports.Engine;  
using CrystalDecisions.Shared;  
  
namespace UsedClothing  
{  
    public partial class BBPV : System.Web.UI.Page  
    {  
        SqlConnection con = new SqlConnection();  
        ReportDocument rpt = new ReportDocument();  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            //if (!IsPostBack)  
            {  
                rpt.Dispose();  
                rpt.Close();  
                loadReport();  
            }  
        }  
        private void loadReport()  
        {  
  
            rpt.Dispose();  
            rpt.Close();  
             con = new SqlConnection("Data Source=SERVER1\\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=ucms;MultipleActiveResultSets=True;");  
  
            try  
            {  
                con.Open();  
                SqlCommand cmd = new SqlCommand("sp_bigbaleprint", con);  
                cmd.CommandType = CommandType.StoredProcedure;  
                cmd.Parameters.AddWithValue("@BID", Request.QueryString["BID"]);  
                SqlDataAdapter da = new SqlDataAdapter(cmd);  
                DataSet ds = new DataSet();  
                da.Fill(ds);  
                //SqlDataAdapter adp = new SqlDataAdapter("select prdno,orderno,Codeitem,prdqty from probale", con);  
                //DataSet ds = new DataSet();  
                //adp.Fill(ds);  
                
                    //ReportDocument rpt = new ReportDocument();  
                    rpt.Load(Server.MapPath("~/CRBB.rpt"));  
                    rpt.SetDataSource(ds.Tables["Table"]);  
                    BBPViewer.ReportSource = rpt;  
                    rpt.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, false, "Bigbalprd");  
            }  
  
            catch (Exception ex)  
            {  
                rpt.Close();  
                rpt.Dispose();  
                con.Close();  
            }  
        }  
        protected void CRBigview_Unload(object sender, EventArgs e)  
        {  
  
  
            if (rpt != null)  
            {  
                rpt.Close();  
                rpt.Dispose();  
  
            }  
  
        }  
  
    }  
}  
  
  
Crystal Report  

206082-image.png

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
3,061 questions
Developer technologies ASP.NET Other
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 30,186 Reputation points Microsoft External Staff
    2022-05-31T03:09:35.573+00:00

    Hi @Analyst_SQL ,
    Maybe you can try the following methods.

    • You need to run "Verify Database" on the report again on the server if you are using SQL Server Native Client.
    • Configure Crystal Reports to run in IIS as a local service instead of a network service and use Integrated Security = True in the connection string
    • When you first installed Crystal Report application, you must install all the files to a particular location on your drive. Please navigate to your drive and you will find the crystalreportviewer folder there.Alternatively, you can look at the wwwroot folder.
    • Check if <identity impersonate="true"/> is added in web.config, if so try removing it.
    • Maybe you don't have enough permissions (try to give right to your directory for asp.net and iis user's)

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.