0

when i run this code after 30 second give me error 'time out expire' . error comming exactly after fill dataset . by the way i add connection time out = 0 to my app config but still the problem is the same . so how i can set connection time out for this dataset

    public void ExportInvoicesAccount()
    {
        var q = from h in hmsdb.TransHdrs
                where h.Account.AccountsContracts.First().AccountsMain.ID == _mainaccid
                && h.PayMethod == "R"
                && h.CancelDate == null
                && h.TransDate >= _fromdate
                && h.TransDate <= _todate

                group h by new
                {
                    amID = h.Account.AccountsContracts.First().AccountsMain.ID,
                    amcode = h.Account.AccountsContracts.First().AccountsMain.Code,
                    amName = h.Account.AccountsContracts.First().AccountsMain.EngName,
                    acccode = h.AccountCode,
                    accid = h.AccountID,
                    accname = h.Account.EngName

                } into qg
                select new
                {
                    amID = qg.Key.amID,
                    amCode = qg.Key.amcode,
                    amName = qg.Key.amName,
                    acccode = qg.Key.acccode,
                    accid = qg.Key.accid,
                    accname = qg.Key.accname
                };
        if (_facccode != "" && _taccccode == "")
        {
            q = q.Where(f => f.acccode == _facccode);
        }

        if (_facccode != "" && _taccccode != "")
        {
            q = q.Where(f => Convert.ToInt32(f.acccode) >= Convert.ToInt32(_facccode) && Convert.ToInt32(f.acccode) <= Convert.ToInt32(_taccccode) && f.acccode != "C" && f.acccode != "10281501مكرر ");
        }


        foreach (var x in q)
        {
            try
            {
                ClaimDS ds = new ClaimDS();
                SP_EClaims_StatmentOfAccountGeneralTableAdapter adapt = new SP_EClaims_StatmentOfAccountGeneralTableAdapter();
                ds.EnforceConstraints = false;
                adapt.Fill(ds.SP_EClaims_StatmentOfAccountGeneral, x.amID, x.accid, 0, _fromdate, _todate, _inout,0,0,0, 0);
                if (ds.SP_EClaims_StatmentOfAccountGeneral.Rows.Count != 0)
                {
                    InvoicesByAcc rptinv = new InvoicesByAcc();
                    rptinv.SetDataSource(ds);
                    ExportOptions expop = new ExportOptions();
                    DiskFileDestinationOptions dfdo = new DiskFileDestinationOptions();
                    PdfRtfWordFormatOptions pdfop = new PdfRtfWordFormatOptions();

                    FolderPath = _path + x.amCode + " - " + x.amName + "\\";
                    bool exists = System.IO.Directory.Exists(FolderPath);
                    if (!exists)
                        System.IO.Directory.CreateDirectory(FolderPath);
                    fpath = FolderPath;

                    rptinv.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                    rptinv.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                    DiskFileDestinationOptions objDiskOpt = new DiskFileDestinationOptions();


                    if (_inout == "O")
                    {
                        objDiskOpt.DiskFileName = FolderPath + "\\" + x.acccode + "-" + "0000" + "-0000" + "-" + "001" + "-OUT" + ".pdf";
                    }
                    else if (_inout == "I")
                    {
                        objDiskOpt.DiskFileName = FolderPath + "\\" + x.acccode + "-" + "0000" + "-0000" + "-" + "001" + "-IN" + ".pdf";
                    }
                    else
                    {
                        objDiskOpt.DiskFileName = FolderPath + "\\" + x.acccode + "-" + "0000" + "-0000" + "-" + "001" + "-ALL" + ".pdf";
                    }
                    rptinv.ExportOptions.DestinationOptions = objDiskOpt;
                    rptinv.Export();
                    rptinv.Dispose();
                    rptinv.Close();
                }

                GC.Collect();
                ds.Dispose();
                ds.Clear();
            }
            catch (Exception ex)
            {
                string logpath = FolderPath + "E_Claim_ErrorLog.txt";
                // This text is added only once to the file.
                if (!File.Exists(logpath))
                {
                    // Create a file to write to.
                    using (StreamWriter sw = File.CreateText(logpath))
                    {
                        //sw.WriteLine(ex.Message + "( " + "AccountMainID: " + x.amID + " - " + "AccountID: " + x.accid + " - "+ "ConsID: " + x.consid + " - " + "MRN: " + x.mrn + " )");
                    }

                }
                // This text is always added, making the file longer over time
                // if it is not deleted.
                using (StreamWriter sw = File.AppendText(logpath))
                {
                    sw.WriteLine(ex.Message + " SP_EClaims_StatmentOfAccountGeneral" + "ExportInvoicesAccount" + "( " + "AccountMainID: " + x.amID + " - " + "AccountID: " + x.accid + " - " + "ConsID: " + "0" + " - " + "MRN: " + "0" + " )");
                }
                //MessageBox.Show(ex.Message + "AccountMainID: " + x.amID + "-"+ "AccountID: " + x.accid + "ConsID: " + x.consid + "MRN: " + x.mrn );
            }
        }
    }
  • https://stackoverflow.com/questions/17049055/entity-framework-what-is-the-current-command-timeout-value – inser Jul 21 '17 at 10:59
  • You are using a strongly typed, auto generated `TableAdapter`, so you can't change the timeout of the `DataAdapter` easily because it's `protected`. But you can extend the class because the auto-generated class is `partial`. I've shown it here(VB.NET): https://stackoverflow.com/a/26139059/284240 – Tim Schmelter Jul 21 '17 at 11:00
  • thank you very much . i follow your steps and its working fine with me now – Emad Hamed Jul 22 '17 at 10:44

0 Answers0