none
Index was outside the bounds of the array -error BackgroundWorker(); RRS feed

  • Question

  • Hi ,
    I am using background process menthod to load data from database in report ,
    BackgroundWorker bw = new BackgroundWorker();

     

    applicaiton is working fine form Devlopment system ,However not from user side ,
    users are getting following error.
    sometime back it used to work but suddenly from last week it started raise this error ,
    exception handled in code try ....catch ,so it raising following error.
    I don't understandnig ,how same code release and database is working for me.

    can someboudy advice me on this ,please.

    "Fail to generate report Index was outside the bounds of the array "

     


    Dev

    Tuesday, July 21, 2009 2:31 PM

Answers

  • Your post is unreadable.  Please edit both of your previous posts, and use the little button to the right of the "HTML" button in the editor, in order to properly format your code for posting on the forums.

    That being said, I'd be willing to bet your issue has to do with the hard coded values in your indexers:

    ds.Tables[6]
    ds.Tables[7]
    etc.

    Your exception handling is working properly, but you're not doing anything with the stack trace.  I would strongly recommend creating a separate class to handle exceptions, and within the methods for that class, go ahead and output all the information about any exceptions you might get to one convenient location, such as the event log.  This way, when the error rears it's ugly head, you'll actually have enough information to track down the error.  Currently, simply showing a MessageBox with the error message isn't going to get you much traction towards solving the issue. 

    David Morton - http://blog.davemorton.net/ - @davidmmorton - ForumsBrowser, a WPF MSDN Forums Client
    • Marked as answer by Dev_1 Thursday, July 23, 2009 1:46 PM
    Tuesday, July 21, 2009 4:23 PM
    Moderator
  • it seems  xrTableCell48_BeforePrint is getting fired on loading data in column from background process,
    please advice.

    Dev
    • Marked as answer by Dev_1 Thursday, July 23, 2009 8:44 AM
    Wednesday, July 22, 2009 1:51 PM

All replies

  • This error has nothing to do with the BackgroundWorker.  It's probably what you're doing within the BackgroundWorker's DoWork event handler.  Check to ensure your loops are correct, and you're not explicitly hardcoding any values in indexers, such as "list[0]" or anything like that.  If you need more help with this, post a full stack trace (including inner exceptions), as well as the code that executes within the DoWork event handler. 
    David Morton - http://blog.davemorton.net/ - @davidmmorton - ForumsBrowser, a WPF MSDN Forums Client
    Tuesday, July 21, 2009 2:42 PM
    Moderator
  • thanks David,

    code in Do_Work-

          delegate void DrawUserContainer(DataSet ds);
            DrawUserContainer draw;

            private  void bw_DoWork(object sender, DoWorkEventArgs e)
            {
                DataSet ds = new DataSet();
                DAL.DataManager.loadOverrideData(ds, _MarginGroupID);
                this.splitContainerOverrides.Panel2.Invoke(draw, new object[] { ds });
            }

    but my I am not understanding by the same code and same database is working at my end,if it could have been some technical problem ,it should not have work at my end sa well , right?

    It's Win applicaiton.

    I am doing following index checking ,in one of function in background process which is inside try catch block ,but that execption is not getting raise ,so  I believe that does not have problem.
    if
    (ds.Tables[0].Rows.Count > 0)



    Dev
    • Edited by Dev_1 Tuesday, July 21, 2009 3:04 PM
    Tuesday, July 21, 2009 2:53 PM
  • thanks David,

    code in Do_Work-

          delegate void DrawUserContainer(DataSet ds);
            DrawUserContainer draw;

            private  void bw_DoWork(object sender, DoWorkEventArgs e)
            {
                DataSet ds = new DataSet();
                DAL.DataManager.loadOverrideData(ds, _MarginGroupID);
                this.splitContainerOverrides.Panel2.Invoke(draw, new object[] { ds });
            }

    but my I am not understanding by the same code and same database is working at my end,if it could have been some technical problem ,it should not have work at my end sa well , right?


    Dev

    I need a stack trace here.  I can't see the issue with this particular problem, largely because the "actual work" has been, rightly, moved into another method, which looks like it might be loadOverrideData. 
    David Morton - http://blog.davemorton.net/ - @davidmmorton - ForumsBrowser, a WPF MSDN Forums Client
    Tuesday, July 21, 2009 2:57 PM
    Moderator
  • David,

    I am not able to get the trace as this is happening in user system not getting reproducible in Devlopment machine ,
    is there any other option?

    Dev
    Tuesday, July 21, 2009 3:16 PM
  • Well, you can try posting the "loadOverrideData" method, and I can take a look at it.  There's a good chance you're trying to get a column from the database that doesn't exist.  SqlDataReader throws this exception when you're trying to access a column that doesn't exist. 


    David Morton - http://blog.davemorton.net/ - @davidmmorton - ForumsBrowser, a WPF MSDN Forums Client
    Tuesday, July 21, 2009 3:23 PM
    Moderator
  •  

    private void UpdateReportDataInReportControl(DataSet ds)
    {
    Size sz = new Size();
    sz.Height =this.splitContainerOverrides.Panel2.Height;
    sz.Width =this.splitContainerOverrides.Panel2.Width;
    xtraOverrideReportsUserControl1.Size = sz;
    UMA.UI.ClientProfile.OverrideReports.XtraOverrideReports overrideReport = new UMA.UI.ClientProfile.OverrideReports.XtraOverrideReports(this); 
     
    string ReportName;
    ReportName ="OverridesReport" + "_" + _MarginGroupID + "_" + DateTime.Now.ToString("ddMMMyyyy"); 
     
    try

    {
    using (DataSet dsMG = new DataSet())
    {

    DAL.DataManager.loadMGDetail(dsMG, _MarginGroupID); 
     
    //Data binding for report's override data

    UMA.UI.ClientProfile.OverrideReports.XtraOverrideReports.dataBindForReport(overrideReport, ds); 
     
    //Data binding for report's Margin Group detail

    UMA.UI.ClientProfile.OverrideReports.XtraOverrideReports.dataBindForReportHeader(overrideReport, dsMG); 
     
    //Cell Binding in report

    UMA.UI.ClientProfile.OverrideReports.XtraOverrideReports.XRBindingOfCells(overrideReport);
    overrideReport.CreateDocument();
    //some default desired formatting

    overrideReportFormat(overrideReport);

    }

    catch (Exception anException)
    {

      MessageBox.Show(String.Format("Fail to generate report{0}", anException.Message));
    }

    xtraOverrideReportsUserControl1.printControl1.PrintingSystem = overrideReport.PrintingSystem;

    xtraOverrideReportsUserControl1.printControl1.PrintingSystem.ExportOptions.PrintPreview.DefaultFileName = ReportName;

    overrideReport.PrintingSystem.Document.Name = ReportName;

    panel1ReportLoading.Visible =false;
    xtraOverrideReportsUserControl1.Visible =true; 
     
    this.splitContainerOverrides.Panel2.Controls.Remove(panel1ReportLoading); 
     
    Control.FromHandle(this.xtraOverrideReportsUserControl1.printControl1.Handle).Refresh(); 
     
    Control.FromHandle(this.splitContainerOverrides.Panel2.Handle).Refresh();
    }

    • Edited by Dev_1 Tuesday, July 21, 2009 5:39 PM
    Tuesday, July 21, 2009 4:12 PM
  •  internal static void dataBindForReport(XtraOverrideReports overrideReport, DataSet ds)
            {
               try
                {
                //binding datasource and tables in dataset Sub-Reports,'ETF Decomposition Suppression' report
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        mgeftOvDtblName = ds.Tables[0].TableName; //used for cell binding
                        (overrideReport.FindControl("EtfDecomSuppDetailReport", true) as DetailReportBand).DataSource = ds;
                        (overrideReport.FindControl("EtfDecomSuppDetailReport", true) as DetailReportBand).DataMember = mgeftOvDtblName;
                    }
                    else
                    {
                        (overrideReport.FindControl("EtfDecomSuppDetailReport", true) as DetailReportBand).Visible = false;
                    }

                //binding datasource and tables in dataset Sub-Reports,'Swap Decomposition Suppression' report
                    if (ds.Tables[1].Rows.Count > 0)
                    {
                        mgswapOvDtblName = ds.Tables[1].TableName; //used for cell binding
                        (overrideReport.FindControl("SwapDecomDetailReport", true) as DetailReportBand).DataSource = ds;
                        (overrideReport.FindControl("SwapDecomDetailReport", true) as DetailReportBand).DataMember = mgswapOvDtblName;
                    }
                    else
                    {
                        (overrideReport.FindControl("SwapDecomDetailReport", true) as DetailReportBand).Visible = false;
                    }

                //binding datasource and tables in dataset Sub-Reports,'Margin Overrides Security' report
                    if (ds.Tables[2].Rows.Count > 0)
                    {
                        mgOvSecDtblName = ds.Tables[2].TableName; //used for cell binding
                        (overrideReport.FindControl("MGOverrideSecurityDetailReport", true) as DetailReportBand).DataSource = ds;
                        (overrideReport.FindControl("MGOverrideSecurityDetailReport", true) as DetailReportBand).DataMember = mgOvSecDtblName;
                    }
                    else
                    {
                        (overrideReport.FindControl("MGOverrideSecurityDetailReport", true) as DetailReportBand).Visible = false;
                    }

                //binding datasource and tables in dataset Sub-Reports,'Margin Overrides CCY' report
                    if (ds.Tables[3].Rows.Count > 0)
                    {
                        mgrOvCcyDtblName = ds.Tables[3].TableName; //used for cell binding
                        (overrideReport.FindControl("MGOverrideCcyDetailReport", true) as DetailReportBand).DataSource = ds;
                        (overrideReport.FindControl("MGOverrideCcyDetailReport", true) as DetailReportBand).DataMember = mgrOvCcyDtblName;
                    }
                    else
                    {
                        (overrideReport.FindControl("MGOverrideCcyDetailReport", true) as DetailReportBand).Visible = false;
                    }
                //binding datasource and tables in dataset Sub-Reports,'Positions Overrides' report report
                    if (ds.Tables[4].Rows.Count > 0)
                    {
                        mgPosOvDtblName = ds.Tables[4].TableName; //used for cell binding
                        (overrideReport.FindControl("PositionOverrideDetailReport", true) as DetailReportBand).DataSource = ds;
                        (overrideReport.FindControl("PositionOverrideDetailReport", true) as DetailReportBand).DataMember = mgPosOvDtblName;
                    }
                    else
                    {
                        (overrideReport.FindControl("PositionOverrideDetailReport", true) as DetailReportBand).Visible = false;
                    }

                //binding datasource and tables in dataset Sub-Reports,'Margin Overrides CCY' report
                    if (ds.Tables[5].Rows.Count > 0)
                    {
                        mgCasOvDtblName = ds.Tables[5].TableName; //used for cell binding
                        (overrideReport.FindControl("CashOverrideDetailReport", true) as DetailReportBand).DataSource = ds;
                        (overrideReport.FindControl("CashOverrideDetailReport", true) as DetailReportBand).DataMember = mgCasOvDtblName;
                    }
                    else
                    {
                        (overrideReport.FindControl("CashOverrideDetailReport", true) as DetailReportBand).Visible = false;
                    }

                //binding datasource and tables in dataset Sub-Reports,'Initial Margin Strategy Override' report
                    if (ds.Tables[6].Rows.Count > 0)
                    {
                        mgStrategyIMOvtblName = ds.Tables[6].TableName; //used for cell binding
                        (overrideReport.FindControl("StrategyIMOverrideDetailReport", true) as DetailReportBand).DataSource = ds;
                        (overrideReport.FindControl("StrategyIMOverrideDetailReport", true) as DetailReportBand).DataMember = mgStrategyIMOvtblName;
                    }
                    else
                    {
                        (overrideReport.FindControl("StrategyIMOverrideDetailReport", true) as DetailReportBand).Visible = false;
                    }

                //binding datasource and tables in dataset Sub-Reports,'Initial Margin Trade Override' report
                    if (ds.Tables[7].Rows.Count > 0)
                    {
                        mgTradeIMOvtblName = ds.Tables[7].TableName; //used for cell binding
                        (overrideReport.FindControl("TradeIMOverrideDetailReport", true) as DetailReportBand).DataSource = ds;
                        (overrideReport.FindControl("TradeIMOverrideDetailReport", true) as DetailReportBand).DataMember = mgTradeIMOvtblName;
                    }
                    else
                    {
                        (overrideReport.FindControl("TradeIMOverrideDetailReport", true) as DetailReportBand).Visible = false;
                    }
            
                   
                //binding datasource and tables in dataset Sub-Reports,'NEA's Overrides' report
                    if (ds.Tables[8].Rows.Count > 0)
                    {
                        mgNEAOvtblName = ds.Tables[8].TableName; //used for cell binding
                        (overrideReport.FindControl("NEAOverrideDetailReport", true) as DetailReportBand).DataSource = ds;
                        (overrideReport.FindControl("NEAOverrideDetailReport", true) as DetailReportBand).DataMember = mgNEAOvtblName;
                    }
                    else
                    {
                        (overrideReport.FindControl("NEAOverrideDetailReport", true) as DetailReportBand).Visible = false;
                    }

                //binding datasource and tables in dataset Sub-Reports,'MRA's Overrides' report
                    if (ds.Tables[9].Rows.Count > 0)
                    {
                        mgMRAOvtblName = ds.Tables[9].TableName; //used for cell binding
                        (overrideReport.FindControl("MRAOverrideDetailReport", true) as DetailReportBand).DataSource = ds;
                        (overrideReport.FindControl("MRAOverrideDetailReport", true) as DetailReportBand).DataMember = mgMRAOvtblName;
                    }
                    else
                    {
                        (overrideReport.FindControl("MRAOverrideDetailReport", true) as DetailReportBand).Visible = false;
                    }

                  }
                  catch (Exception anException)
                  {
                      MessageBox.Show(String.Format("Failed to intilization Report{0} ", anException.Message));
                  }
              }
            internal static void dataBindForReportHeader(XtraOverrideReports overrideReport, DataSet dsMG)
            {
                try
                {
           
                    if (dsMG.Tables["MGDetail"].Rows.Count > 0)
                    {
                       overrideReport.DataSource = dsMG;
                    }
                }
                catch (Exception anException)
                {
                    string newMessage = "Failed to intilization Report Header" + anException.Message;
                    Exception aNewException = new Exception(newMessage, anException);
                    throw aNewException;
                }
            }

    • Edited by Dev_1 Tuesday, July 21, 2009 5:32 PM
    • Marked as answer by Dev_1 Thursday, July 23, 2009 1:46 PM
    • Unmarked as answer by Dev_1 Thursday, July 23, 2009 1:46 PM
    Tuesday, July 21, 2009 4:20 PM
  • Your post is unreadable.  Please edit both of your previous posts, and use the little button to the right of the "HTML" button in the editor, in order to properly format your code for posting on the forums.

    That being said, I'd be willing to bet your issue has to do with the hard coded values in your indexers:

    ds.Tables[6]
    ds.Tables[7]
    etc.

    Your exception handling is working properly, but you're not doing anything with the stack trace.  I would strongly recommend creating a separate class to handle exceptions, and within the methods for that class, go ahead and output all the information about any exceptions you might get to one convenient location, such as the event log.  This way, when the error rears it's ugly head, you'll actually have enough information to track down the error.  Currently, simply showing a MessageBox with the error message isn't going to get you much traction towards solving the issue. 

    David Morton - http://blog.davemorton.net/ - @davidmmorton - ForumsBrowser, a WPF MSDN Forums Client
    • Marked as answer by Dev_1 Thursday, July 23, 2009 1:46 PM
    Tuesday, July 21, 2009 4:23 PM
    Moderator
  • Thanks David,
    (actaully this page and Frames on it are behaving strangly so not able put the post correctly )
    Dev
    Tuesday, July 21, 2009 5:09 PM
  • Heay David,

    I am able to get the trace as you guide ealier ,
    I don't unserdtand why it is raising error ni this part,

    2009-07-22 13:40:22,806 [ELONW115212-2009-07-22T12:39:11-4968 Mesh Main UI Thread 0x1] ERROR DAL.DataManager  [(null)] - Fail to generate report Index was outside the bounds of the array.   at UMA.UI.ClientProfile.OverrideReports.XtraOverrideReports.xrTableCell48_BeforePrint(Object sender, PrintEventArgs e)
       at DevExpress.XtraReports.UI.XRControl.OnBeforePrint(PrintEventArgs e)
       at DevExpress.XtraReports.UI.XRControl.GetPrintableBrick(PrintingSystem ps)
       at DevExpress.XtraReports.UI.XRControl.GetPrintableBrick(PrintingSystem ps)
       at DevExpress.XtraReports.UI.XRControl.GetPrintableBrick(PrintingSystem ps)
       at DevExpress.XtraReports.UI.XRControl.WriteContentTo(XRWriteInfo writeInfo)
       at DevExpress.XtraReports.UI.Band.GenerateContent(DocumentBand docBand, Int32 rowIndex, Boolean fireBeforePrint)
       at DevExpress.XtraReports.UI.Band.GenerateWithSubreports(DocumentBand docBand, Int32 rowIndex, Boolean fireBeforePrint)
       at DevExpress.XtraReports.Native.SelfGeneratedDocumentBand..ctor(RootDocumentBand root, DocumentBandKind kind, Band band, Int32 rowIndex, Boolean fireBeforePrint)
       at DevExpress.XtraReports.UI.Band.CreateDocumentBand(Int32 rowIndex, RootDocumentBand rootDocBand)
       at DevExpress.XtraReports.UI.DetailBand.CreateDocumentBand(Int32 rowIndex, Int32 rowCount, RootDocumentBand rootDocBand)
       at DevExpress.XtraReports.Native.Printing.DetailWriterBase.WriteDetailCore()
       at DevExpress.XtraReports.Native.Printing.DetailWriterBase.Write()
       at DevExpress.XtraReports.Native.Printing.DocumentBuilder.Build()
       at DevExpress.XtraReports.UI.XtraReportBase.BuildDocument(DocumentBuilder builder)
       at DevExpress.XtraReports.UI.DetailReportBand.BuildDocument(DocumentBuilder builder)
       at DevExpress.XtraReports.UI.XtraReportBase.WriteToDocument(DocumentBuilder docBuilder)
       at DevExpress.XtraReports.Native.Printing.DetailWriterBase.WriteDetailCore()
       at DevExpress.XtraReports.Native.Printing.DetailWriterBase.Write()
       at DevExpress.XtraReports.Native.Printing.DocumentBuilder.Build()
       at DevExpress.XtraReports.Native.Printing.RootReportBuilder.Build()
       at DevExpress.XtraReports.UI.XtraReportBase.BuildDocument(DocumentBuilder builder)
       at DevExpress.XtraReports.UI.XtraReport.CreateDocumentCore2(PrintingSystem ps, Single progressRange)
       at DevExpress.XtraReports.UI.XtraReport.CreateDocumentCore(Single progressRange)
       at DevExpress.XtraReports.UI.XtraReport.CreateDocument(Single progressRange)
       at DevExpress.XtraReports.UI.XtraReport.CreateDocument()
       at UMA.UI.ClientProfile.ClientProfileEdit.UpdateReportDataInReportControl(DataSet ds)


     

    private void xrTableCell48_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
    {
    string[] parts = (sender as XRControl).Text.Split(' ');
    if (parts.Length == 2)
    {
          (sender
    as XRControl).Text = parts[0] + "\n" + parts[1] + " " + parts[2];
    }
    }


    Dev
    Wednesday, July 22, 2009 12:58 PM
  • it seems  xrTableCell48_BeforePrint is getting fired on loading data in column from background process,
    please advice.

    Dev
    • Marked as answer by Dev_1 Thursday, July 23, 2009 8:44 AM
    Wednesday, July 22, 2009 1:51 PM
  • Issue is resolved.
    following piece of code was getting called in user side ,before report loading or during loading ....when there was no item in the array

    which needed to be fixed with correct item count.
    parts.Length == 3

    if (parts.Length == 3)
    {
          (sender as XRControl).Text = parts[0] + "\n" + parts[1] + " " + parts[2];
    }


    Dev
    Thursday, July 23, 2009 8:44 AM
  • Issue is resolved.
    following piece of code was getting called in user side ,before report loading or during loading ....when there was no item in the array

    which needed to be fixed with correct item count.
    parts.Length == 3

    if (parts.Length == 3)
    {
          (sender as XRControl).Text = parts[0] + "\n" + parts[1] + " " + parts[2];
    }


    Dev
    Isn't this exactly what I've been saying the whole time?  If it is, and you wouldn't mind, I'd appreciate it if my post was the one marked as answer here.  Also, the post you marked won't make much sense if someone comes googling a solution later here.  They don't have the same methods as you.  
    David Morton - http://blog.davemorton.net/ - @davidmmorton - ForumsBrowser, a WPF MSDN Forums Client
    Thursday, July 23, 2009 10:19 AM
    Moderator
  • Thanks David.


    Dev
    Thursday, July 23, 2009 1:47 PM