Hello experts,
I had been creating SSRS using Vs2010 and SQL 2008 R2,
recently i formatted my pc and installed Windows 10, Vs2013, SQL 2016,
intermittently i am getting error while a call to Render port is given
byte[] bytes = lr.Render(fileExt, null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);
these gets called from
ExportShdlVsDisp
emailsend
why the localreport.render is giving following error
at Microsoft.Reporting.WinForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings)
at Microsoft.Reporting.WinForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams,
Warning[]& warnings)
at Microsoft.Reporting.WinForms.LocalReport.Render(String format, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
at Microsoft.Reporting.WinForms.Report.Render(String format, String deviceInfo, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
at Kings.ERP.SaleReports.ExportShdlVsDisp(LocalReport lr, String filename, String fileExt) in d:\13vs\Kings ERP\Reports\SalesReports.cs:line 958
Microsoft.Reporting.WinForms.LocalProcessingException: An error occurred during local report processing. ---> Microsoft.ReportingServices.Diagnostics.Utilities.RSException: Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: The specified
operation is not valid. ---> Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: The specified operation is not valid.
at Microsoft.ReportingServices.RdlExpressions.ReportRuntime.RegisterRuntimeErrorInExpression(VariantResult& result, Exception e, IErrorContext iErrorContext, Boolean isError)
at Microsoft.ReportingServices.RdlExpressions.ReportRuntime.RegisterRuntimeErrorInExpression(VariantResult& result, Exception e)
at Microsoft.ReportingServices.RdlExpressions.ReportRuntime.EvaluateTextRunValueExpression(TextRun textRun)
at Microsoft.ReportingServices.ReportProcessing.OnDemandReportObjectModel.TextRunImpl.GetResult(IReportScopeInstance romInstance)
at Microsoft.ReportingServices.ReportIntermediateFormat.TextRun.EvaluateValue(IReportScopeInstance instance, OnDemandProcessingContext context)
at Microsoft.ReportingServices.OnDemandReportRendering.InternalTextRunInstance.EvaluateOriginalValue()
at Microsoft.ReportingServices.OnDemandReportRendering.InternalTextRunInstance.get_ProcessedWithError()
at Microsoft.ReportingServices.OnDemandReportRendering.TextBoxInstance.get_ProcessedWithError()
at Microsoft.ReportingServices.Rendering.SPBProcessing.TextBox.WriteCustomNonSharedItemProps(RPLElementProps nonSharedProps, RPLWriter rplWriter, PageContext pageContext)
at Microsoft.ReportingServices.Rendering.SPBProcessing.PageItem.WriteNonSharedItemProps(RPLElementProps elemProps, RPLWriter rplWriter, PageContext pageContext)
at Microsoft.ReportingServices.Rendering.SPBProcessing.PageElement.WriteElementProps(RPLElementProps elemProps, RPLWriter rplWriter, PageContext pageContext)
at Microsoft.ReportingServices.Rendering.SPBProcessing.TextBox.WriteItemToStream(RPLWriter rplWriter, PageContext pageContext)
at Microsoft.ReportingServices.Rendering.SPBProcessing.TextBox.CalculatePage(RPLWriter rplWriter, PageItemHelper lastPageInfo, PageContext pageContext, PageItem[] siblings, RepeatWithItem[] repeatWithItems, Double parentTopInPage, Double& parentPageHeight,
Interactivity interactivity)
at Microsoft.ReportingServices.Rendering.SPBProcessing.Tablix.TablixContext.CalculateDetailCell(PageItem topItem, Int32 colIndex, Boolean collect, PageContext pageContext)
at Microsoft.ReportingServices.Rendering.SPBProcessing.Tablix.TablixContext.AddDetailCell(TablixCell cellDef, Int32 colIndex, Double cellColDefWidth, Double cellCellDefHeight, Boolean ignoreCellPageBreaks, Boolean collect, Boolean& partialItem)
at Microsoft.ReportingServices.Rendering.SPBProcessing.Tablix.CreateDetailCell(Tablix tablix, TablixMember colMemberParent, Int32 colGridIndex, TablixContext context)
at Microsoft.ReportingServices.Rendering.SPBProcessing.Tablix.CreateColumnMemberChildren(Tablix tablix, TablixMember colMemberParent, Int32 defTreeLevel, Boolean parentBorderHeader, Int32 parentRowIndex, Int32 parentColIndex, TablixContext context,
Boolean createDetail, LevelInfo& parentLevelInfo)
at Microsoft.ReportingServices.Rendering.SPBProcessing.Tablix.CreateColumnMemberChildren(Tablix tablix, TablixMember colMemberParent, Int32 defTreeLevel, Boolean parentBorderHeader, Int32 parentRowIndex, Int32 parentColIndex, TablixContext context,
Boolean createDetail, LevelInfo& parentLevelInfo)
at Microsoft.ReportingServices.Rendering.SPBProcessing.Tablix.CreateRowMemberChildren(Tablix tablix, TablixMember rowMemberParent, InnerToggleState parentToggleState, Int32 defTreeLevel, Boolean parentBorderHeader, Int32 parentRowIndex, Int32 parentColIndex,
Int32 level, TablixContext context, Boolean& advanceRow, LevelInfo& parentLevelInfo, List`1& ignoreTotals, Boolean keepTogether)
at Microsoft.ReportingServices.Rendering.SPBProcessing.Tablix.CreateRowMemberChildren(Tablix tablix, TablixMember rowMemberParent, InnerToggleState parentToggleState, Int32 defTreeLevel, Boolean parentBorderHeader, Int32 parentRowIndex, Int32 parentColIndex,
Int32 level, TablixContext context, Boolean& advanceRow, LevelInfo& parentLevelInfo, List`1& ignoreTotals, Boolean keepTogether)
at Microsoft.ReportingServices.Rendering.SPBProcessing.Tablix.CreateRowMemberChildren(Tablix tablix, TablixMember rowMemberParent, InnerToggleState parentToggleState, Int32 defTreeLevel, Boolean parentBorderHeader, Int32 parentRowIndex, Int32 parentColIndex,
Int32 level, TablixContext context, Boolean& advanceRow, LevelInfo& parentLevelInfo, List`1& ignoreTotals, Boolean keepTogether)
at Microsoft.ReportingServices.Rendering.SPBProcessing.Tablix.CreateTablixItems(Tablix tablix, TablixContext context)
at Microsoft.ReportingServices.Rendering.SPBProcessing.Tablix.CalculatePage(RPLWriter rplWriter, PageItemHelper lastPageInfo, PageContext pageContext, PageItem[] siblings, RepeatWithItem[] repeatWithItems, Double parentTopInPage, Double& parentPageHeight,
Interactivity interactivity)
at Microsoft.ReportingServices.Rendering.SPBProcessing.ReportBody.CalculatePage(RPLWriter rplWriter, PageItemHelper lastPageInfo, PageContext pageContext, PageItem[] siblings, RepeatWithItem[] repeatWithItems, Double parentTopInPage, Double&
parentPageHeight, Interactivity interactivity)
at Microsoft.ReportingServices.Rendering.SPBProcessing.ReportSection.CalculatePage(RPLWriter rplWriter, Int32 page, Int32 totalPages, Int32 regionPageNumber, Int32 regionTotalPages, Boolean firstSectionOnPage, Boolean lastSection, Interactivity
interactivity, Double heightToBeUsed, PageItemHelper& lastBodyInfo, Boolean& delayedHeader, Boolean& delayedFooter, Boolean& lastSectionOnPage)
at Microsoft.ReportingServices.Rendering.SPBProcessing.Report.NextPage(RPLWriter rplWriter, ReportSectionHelper& lastPageInfo, Int32 page, Int32 totalPages, Interactivity interactivity, Boolean hasPaginationChunk)
at Microsoft.ReportingServices.Rendering.SPBProcessing.SPBProcessing.GetReportNextPage(Stream& stream, Boolean collectPageBookmarks)
at Microsoft.ReportingServices.Rendering.SPBProcessing.SPBProcessing.GetNextPage(RPLReport& rplReport, Boolean collectPageBookmarks)
at Microsoft.ReportingServices.Rendering.SPBProcessing.SPBProcessing.GetNextPage(RPLReport& rplReport)
at Microsoft.ReportingServices.Rendering.ExcelRenderer.ExcelRenderer.Render(Report report, NameValueCollection reportServerParameters, NameValueCollection deviceInfo, NameValueCollection clientCapabilities, Hashtable& renderProperties, CreateAndRegisterStream
createAndRegisterStream)
--- End of inner exception stack trace ---
at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.HandleRenderingException(ReportRenderingException rex)
at Microsoft.ReportingServices.ReportProcessing.Execution.RenderReport.Execute(IRenderingExtension newRenderer)
at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.RenderReport(IRenderingExtension newRenderer, DateTime executionTimeStamp, ProcessingContext pc, RenderingContext rc, IChunkFactory yukonCompiledDefinition)
at Microsoft.Reporting.LocalService.CreateSnapshotAndRender(ReportProcessing repProc, IRenderingExtension renderer, ProcessingContext pc, RenderingContext rc, SubreportCallbackHandler subreportHandler, ParameterInfoCollection parameters, DatasourceCredentialsCollection
credentials)
at Microsoft.Reporting.LocalService.Render(String format, String deviceInfo, String paginationMode, Boolean allowInternalRenderers, IEnumerable dataSources, CreateAndRegisterStream createStreamCallback)
at Microsoft.Reporting.WinForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings)
--- End of inner exception stack trace ---
at Microsoft.Reporting.WinForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream createStreamCallback, Warning[]& warnings)
at Microsoft.Reporting.WinForms.LocalReport.InternalRender(String format, Boolean allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams,
Warning[]& warnings)
at Microsoft.Reporting.WinForms.LocalReport.Render(String format, String deviceInfo, PageCountMode pageCountMode, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
at Microsoft.Reporting.WinForms.Report.Render(String format, String deviceInfo, String& mimeType, String& encoding, String& fileNameExtension, String[]& streams, Warning[]& warnings)
at Kings.ERP.SaleReports.ExportShdlVsDisp(LocalReport lr, String filename, String fileExt) in d:\13vs\Kings ERP\Reports\SalesReports.cs:line 958
how can i understand what is going wrong in Localreport Render
private void emailsend()
{
try
{
var outlookType = Type.GetTypeFromProgID("Outlook.Application");
if (outlookType == null)
{
MessageBox.Show("Outlook Not Installed");
return;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Properties.Settings.Default.ShdlVsDispatchCC = txtCC.Text;
pgbEmail.PerformStep();
try
{
using (SqlConnection con = new SqlConnection(Appvaribales.ConnectionString))
{
string scheduleperiod = dtpFrom.Value.ToString("yyyyMMdd") + '-' + dtpto.Value.ToString("yyyyMMdd");
SqlCommand cmd = new SqlCommand();
int fromid=0, uptoid=0;
if (Properties.Settings.Default.GateOutEntry.Equals(true))
{
int.TryParse(txtserialfrm.Text, out fromid);
int.TryParse(txtserialupto.Text, out uptoid);
cmd = new SqlCommand("ShdlVsDispAccountsGE", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@plantid", ErpMdi1.ID));
cmd.Parameters.Add(new SqlParameter("@doc_gls", doc_gls));
cmd.Parameters.Add(new SqlParameter("@fromdate", dtpDispatchedOn.Value.ToString("yyyyMMdd")));
cmd.Parameters.Add(new SqlParameter("@todate", dtpDispatchedOn.Value.ToString("yyyyMMdd")));
cmd.Parameters.Add(new SqlParameter("@controlgl", controlgl));
cmd.Parameters.Add(new SqlParameter("@acslfrom", AcSLFrom));
cmd.Parameters.Add(new SqlParameter("@acslto", AcSLTo));
cmd.Parameters.Add(new SqlParameter("@fromid", fromid));
cmd.Parameters.Add(new SqlParameter("@uptoid", uptoid));
}
else
{
cmd = new SqlCommand("ShdlVsDispAccounts", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@plantid", ErpMdi1.ID));
cmd.Parameters.Add(new SqlParameter("@doc_gls", doc_gls));
cmd.Parameters.Add(new SqlParameter("@fromdate", dtpFrom.Value.ToString("yyyyMMdd")));
cmd.Parameters.Add(new SqlParameter("@todate", dtpto.Value.ToString("yyyyMMdd")));
cmd.Parameters.Add(new SqlParameter("@controlgl", controlgl));
cmd.Parameters.Add(new SqlParameter("@acslfrom",AcSLFrom));
cmd.Parameters.Add(new SqlParameter("@acslto",AcSLTo));
}
//DataSet dsAl = new DataSet("AccountList");
//Fill Table Fill
con.Open();
DataTable dtAl = new DataTable();
dtAl.Load(cmd.ExecuteReader());
DataTable dtcompany = new DataTable();
cmd.CommandText = "select top 1 * from company";
cmd.CommandType = CommandType.Text;
dtcompany.Load(cmd.ExecuteReader());
con.Close();
// http://msdn.microsoft.com/en-us/library/ms252091(v=vs.80).aspx
//http://www.codeproject.com/Tips/165548/C-Code-snippet-to-send-an-Email-with-attachment-fr
//Walkthrough: Printing a Local Report without Preview http://msdn.microsoft.com/en-us/library/ms252091%28VS.80%29.aspx
// Printing Reports Programmatically Using C# and SQL Server 2000 Reporting Services http://blogs.msdn.com/b/bryanke/archive/2004/02/11/71491.aspx
LocalReport lr = new LocalReport();
lr.SubreportProcessing += new Microsoft.Reporting.WinForms.SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
lr.ReportPath = lblReportFile.Text;
string emailreport;
string plantid = ErpMdi1.ID.ToString();
//
//ReportParameter p1 = new ReportParameter("plantid", plantid);
ReportParameter p2 = new ReportParameter("fromdate", dtpFrom.Value.ToShortDateString());
ReportParameter p3 = new ReportParameter("todate", dtpto.Value.ToShortDateString());
lr.SetParameters(new ReportParameter[] { p2, p3 });
#region
//
// MailMessage myMail = new MailMessage();
// MailAddress mail_address = new MailAddress(txtFromMailID.Text.ToString());
// SmtpClient smtpcl = new SmtpClient(ConfigurationManager.AppSettings["mail_server"].ToString(), Int32.Parse(ConfigurationManager.AppSettings["mail_port"]));
// myMail.From = mail_address;
// myMail.Subject = scheduleperiod;
// myMail.Body = @"Dear Sir,
// Kindly see The Schedule Vs. Dispatches Report.
// Developed By www.kingsiq.com";
// smtpcl.Credentials = new NetworkCredential(txtFromMailID.Text.ToString(), txtPassword.Text.Trim());
// smtpcl.EnableSsl = true;
// smtpcl.EnableSsl = true;
#endregion
int emailscount = 0;
if (dtAl.Rows.Count > 0)
pgbEmail.Step = 100 / dtAl.Rows.Count;
else
pgbEmail.Step = 1;
foreach (DataRow dtr in dtAl.Rows)
{
if (!String.IsNullOrWhiteSpace(dtr["email_id"].ToString().Trim()))
{
lr.DataSources.Clear();
lr.DataSources.Add(new ReportDataSource("DataSet1", LoadShdlVsDispData(dtr["ac_code"].ToString())));
lr.DataSources.Add(new ReportDataSource("company", dtcompany));
emailscount++;
lblemailsent2.Text = emailscount.ToString() + "/" + dtAl.Rows.Count.ToString() + " - "+ dtr["name"].ToString();
lblemailsent2.Refresh();
emailreport = ExportShdlVsDisp(lr, ErpMdi1.dtLoggedAt.ToString("yyyyMMdd") + "-ShdlVsDisp", cmbOutputFormat.SelectedItem.ToString());
Outlook.Application oApp = new Outlook.Application();
// Get the NameSpace and Logon information.
Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
// Log on by using a dialog box to choose the profile.
oNS.Logon(Missing.Value, Missing.Value, true, true);
// Alternate logon method that uses a specific profile.
// TODO: If you use this logon method,
// change the profile name to an appropriate value.
//oNS.Logon("YourValidProfile", Missing.Value, false, true);
// Create a new mail item.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
// Set the subject.
oMsg.Subject = txtMsgSubject.Text;
// Set HTMLBody.
string currdispatches = "";
//SQL Function Example
SqlCommand cmddispatch = new SqlCommand("select dbo.CustomerDispatchDated(@shipdate,@ac_code,@fromid,@uptoid)", con);
cmddispatch.CommandType = CommandType.Text;
cmddispatch.Parameters.Add(new SqlParameter("@shipdate", dtpDispatchedOn.Value.ToString("yyyyMMdd")));
cmddispatch.Parameters.Add(new SqlParameter("@ac_code", LoadShdlVsDispData(dtr["ac_code"].ToString()).ToString()));
cmddispatch.Parameters.Add(new SqlParameter("@fromid", fromid));
cmddispatch.Parameters.Add(new SqlParameter("@uptoid", uptoid));
try
{
if (con.State == ConnectionState.Closed)
con.Open();
currdispatches = (string)cmddispatch.ExecuteScalar();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
oMsg.HTMLBody = " Dispatched on:" + dtpDispatchedOn.Value.ToShortDateString()+
System.Environment.NewLine +
txtMsgBody.Text +
System.Environment.NewLine +
currdispatches+
System.Environment.NewLine +"Developed by:Sushil Agarwal (+91 98226 10809)";
// Add a recipient.
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
// TODO: Change the recipient in the next line if necessary.
string[] receipants = dtr["email_id"].ToString().Split(';');
for (int i = 0; i < receipants.Length; i++)
{
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(receipants[i]);
oRecip.Resolve();
}
//Add CC
if (!string.IsNullOrWhiteSpace(txtCC.Text))
{
string[] Receipantscc = txtCC.Text.Split(';');
for (int i = 0; i < Receipantscc.Length; i++)
{
Outlook.Recipient recipientCC = oRecips.Add(Receipantscc[i]);
recipientCC.Type = (int)Outlook.OlMailRecipientType.olCC;
recipientCC.Resolve();
}
}
//Add BCC
//if (!string.IsNullOrWhiteSpace(txtBCC.Text))
//{
// Outlook.Recipient recipientBCC = oRecips.Add(txtCC.Text);
// recipientBCC.Type = (int)Outlook.OlMailRecipientType.olBCC;
// recipientBCC.Resolve();
//}
//now attached the file
if (!string.IsNullOrWhiteSpace(emailreport))
{
//Add an attachment.
String sDisplayName = "ScheduleVsDispatch";
int iPosition = (int)oMsg.Body.Length + 1;
int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
Outlook.Attachment oAttach = oMsg.Attachments.Add(emailreport, iAttachType, iPosition, sDisplayName);
}
// Send.
//31.7.2016
oMsg.Send();
// Log off.
oNS.Logoff();
// Clean up.
//oRecip = null;
oRecips = null;
oMsg = null;
oNS = null;
oApp = null;
if (!string.IsNullOrWhiteSpace(emailreport))
File.Delete(emailreport);
//Direct email without outllok usinh gmail sender example
//Attachment attachCh = new Attachment(emailreport, MediaTypeNames.Application.Octet);
//myMail.Attachments.Add(attachCh);
//myMail.To.Add(dtr["email_id"].ToString());
//smtpcl.Send(myMail);
//myMail.To.Clear();
//myMail.Attachments.Clear();
}
if (pgbEmail.Value == pgbEmail.Maximum)
{
pgbEmail.Value = pgbEmail.Minimum;
}
else
{
//pgbEmail.Value += 1;
pgbEmail.PerformStep();
}
}
// email attachemnt delete is not working error:use by another process, unsolved till :25.8.2011 san
//myMail.Attachments.Dispose();
//foreach (DataRow dtr in dtAl.Rows)
//{
// string filename = Path.Combine(Path.GetTempPath(), dtr["short_name"].ToString() + "-" + scheduleperiod + "-ShdlVsDisp.pdf");
// if (File.Exists( filename))
// File.Delete(filename );
pgbEmail.Value = 100;
MessageBox.Show("e-mails Sent");
pgbEmail.Value = pgbEmail.Minimum;
}
}
catch (ReportViewerException ex)
{
MessageBox.Show(ex.ToString());
}
}
private string ExportShdlVsDisp(LocalReport lr, string filename = "scheduleVSdispatch", string fileExt="PDF" )
{
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string filenameExtension="";
string outfilename = Path.Combine(Path.GetTempPath(), filename);
//byte[] bytes1 = lr.Render("Excel",null,out mimeType,out encoding,out filenameExtension,out streamids,out warnings);
try
{
byte[] bytes = lr.Render(fileExt, null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);
using (FileStream fs = new FileStream(outfilename + "." + filenameExtension, FileMode.Create))
{
fs.Write(bytes, 0, bytes.Length);
}
}
catch (Exception ex)
{
//MessageBox.Show(ex.ToString());
}
if (string.IsNullOrWhiteSpace(filenameExtension))
return "";
else
return outfilename + "." + filenameExtension;
}