Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9269

Re: Pagination With Crystal report in Asp.net

$
0
0

Hi,

 

    Thanks for reply and help

    Here is the step to re-create issue(I have installed crystal report 13 with visual studio 2010)

 

1) Create one sample web application with asp.net 4.0

2) create one sample crystal report with simple subreport type.

3) Add 2 table inside sql and insert around 1000 records  and write a procedure to retrieve that record.

4) add following line inside web application's web.config file.

    <sessionState allowCustomSqlDatabase="true" compressionEnabled="true" timeout="120" mode="SQLServer" sqlConnectionString="Data Source=SERVER;Initial Catalog=TESTDB;User ID=rt;Password=PASSWORD">

5) now add one .aspx page without master page and add following code inside it.

    .Aspx code

 

 

<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"  Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

 

inside <div> tag

<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True" BestFitPage="True"

                        EnableDatabaseLogonPrompt="False" HasCrystalLogo="False" Height="100%" Width="100%" />

 

6) now add following code inside .cs file

 

public partial class ReportTest :  System.Web.UI.Page

    {

        ReportDocument rptTest= new ReportDocument();

        protected void Page_Init(object sender, EventArgs e)  // or wrote in Page_Load

        {

            DataTable dtMain = new DataTable();

            DataTable dtSubReport = new DataTable();         

            try

            {

                 if (!IsPostBack)

                {

                    string ruleType = Request.QueryString["type"];

                    if (!string.IsNullOrEmpty(ruleType))

                    {

                        dtMain.Clear();

                        SqlParameter[] sqlMainPara = new SqlParameter[2];

                        string reportName =  "testReport";

 

                          if (ruleType.Equals("1"))

                        {

                            sqlMainPara[0] = new SqlParameter("typ", "123");

                        }

                        else if (ruleType.Equals("2"))

                        {

                            sqlMainPara[0] = new SqlParameter("Grp", "222");

                        }

                        sqlMainPara[1] = new SqlParameter("stype", "234");

                        rptMainDoc.Load(Server.MapPath(@"~\Reports\RptFile testreport.rpt"));                                  dtMain = DbFactory.GetDataByProcedure("myproc", sqlMainPara).Tables[0];

                   rptMainDoc.SetDataSource(dtMain);

                   sqlMainPara = new SqlParameter[0];

                   dtSubReport.Clear();

                   dtSubReport = DbFactory.GetDataByProcedure("getSubReport", sqlMainPara).Tables[0];

                        foreach (ReportObject repOp in rptMainDoc.ReportDefinition.ReportObjects)

                        {

                            if (repOp.Kind == ReportObjectKind.SubreportObject)

                            {

                                string SubRepName = ((SubreportObject)repOp).SubreportName;

                                ReportDocument subRepDoc = rptMainDoc.Subreports[SubRepName];

                                subRepDoc.SetDataSource(dtSubReport);

                            }

                        }                     

                        BindCrystal();                      

                    }

                }

                else

                {

                    BindCrystal(); // this is for pagination.

                }

            }

            catch (Exception ex)

            {

               

                ClientScript.RegisterStartupScript(typeof(System.Web.UI.Page), "alertuser", "<script>alert('Sorry error occurred in report.');</script>", false);

            }

            finally

            {

                dtMain.Dispose();

                dtSubReport.Dispose();  

            }

        }

        private void BindCrystal()

        {

            if (Session["MyTest"] == null)

            {

                Session["MyTest"] = rptMainDoc;

            }

            CrystalReportViewer1.ReportSource =(ReportDocument)Session["MyTest"];

            CrystalReportViewer1.ReuseParameterValuesOnRefresh = false;

            CrystalReportViewer1.EnableParameterPrompt = false;

            CrystalReportViewer1.HasRefreshButton = false; // this is set to false because giving parameter missing error.

            CrystalReportViewer1.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;

        }

        protected void Page_Unload(object sender, EventArgs e)

        {

            CrystalReportViewer1.Dispose();

            rptMainDoc.Dispose();

        }

 

7) run web application then getting this error.(please have a look attached SqlServerStateError.jpg image)SqlServerStateError.jpg

8) now try to remove sql server state from web.config and still you will get run time other error.

 

now my question is

 

I use session to restrict query execution on each and every crystal report pagination click...


1) how to dispose or set null inside  Session["MyTest"] and when i should set null ? because page_unload event fire every time when i click on pagination.

 

2) now to overcome this type situation i store DataTable inside Session but still problem is that when i can clear that session ? because I can not determine that user is going to close crystal report or .aspx page

 

Hope you understand my problem now,if still you are not able to understand my problem then let me know i will send you more detail.

 

While scenario i am testing with Chrome browser because my client is mostly using it and my application is intranet base.

 

Thanks for help.


Viewing all articles
Browse latest Browse all 9269

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>