When generating a RDLC report in a C#/WPF application, sometimes it hangs on render (call of render method doesn't return).
The report data comes from a C# object (which is filled in advance with data from a PostgreSQL database) so this issue is not SQL related.
I wonder:
How can I find out the reason?
Is there any way to enable the user to kill the report generation when it hangs?
Embedding the report generation in a using block (as seen in ReportViewer rendering hangs server after some executions) didn't solve the problem.
using (LocalReport report = new LocalReport())
{
report.ReportPath = #"C:\Path\To\MyReport.rdlc";
// Get the report data from db and fill it into MyReportData object.
MyReportData data = CreateReportData();
ReportDataSource headerDataSource = new ReportDataSource();
headerDataSource.Name = "HeaderDataSet";
headerDataSource.Value = data.Header;
report.DataSources.Add(headerDataSource);
// Add more data sources ...
// No report parameters are being used
report.Refresh();
pdfData = report.Render("PDF"); // here it hangs sometimes
}
As said above, the render-call hangs sometimes. After killing the application and generating exactly the same report again it works.
Dear all I am working on an asp .net application (Webform) in which I am using crystal report for showing reports (with store procedure ).
In my application everything works fine including the reports. The real problem comes when I start clicking on the crystal report toolbar. If I click on any buttons on the crystal report tool bar like (Export, next page ...etc.) it is asking parameters again. Is there any way so that that the crystal report viewer does not ask the parameter that I have already given ?
ReportDocument r = new ReportDocument();
r.Load(Server.MapPath("~/Consumers/Reports/JobOrder.rpt"));
SqlParameter[] para= new SqlParameter[1];
para[0]= new SqlParameter("#OrderId",JobOrder);
dt=da.ExecuteQuery("sp_rpt_JobOrder",para);
if(dt.Rows.Count>0)
{
r.SetParameterValue("#OrderId", JobOrder);
r.SetDataSource(dt);
CrystalReportViewer1.ReportSource = r;
}
can some one help me? Highly appreciated.
its causing due to post back. so i removed
if (!Page.IsPostBack)
now its working fine for me.
Thank you.
I was made to print a report in C#. But I found the error. For the first print run normally. But for the second time, my program is immediately stopped.
The window error is something like that :
has encountered a problem and needs to close. we are sorry for the inconvenience
The code is :
ReportDocument rptDocument = new ReportDocument();
PrinterSettings settings = new PrinterSettings();
public void cetak() {
rptDocument.Load(Application.StartupPath + "/report/fakturpenjualan.rpt");
rptDocument.SetParameterValue("idpenjualan", idp);
rptDocument.PrintOptions.PrinterName = settings.PrinterName;
rptDocument.PrintToPrinter(1, true, 0, 0);
rptDocument.Close();
}
What should I do?
Be sure and DISPOSE the object after closing it and force a garbage collection. The runtime engine has issues if the report object is not completely destroyed.
recently I went from CR Basic for VS2008, to CR 13.0.2 (for VS 2010) on Windows 7 (64 bit) and Iam using .NET 4.5 framework.
In VS2008 all was working fine, now I get the "Database logon failed" error, and I DO NOT use any database. I only fill Parameter and Formula fields on the Crystal Report, and try to print it out. As mentioned, in VS 2008 all was woking OK, now its not. Why so??
Here is my simple code:
//passing data to parameters like (one example):
cr1.SetParameterValue("ParameterName", Actual_Parameter);
//and my code for prinitng:
PrintDocument doctoprint = new PrintDocument();
doctoprint.PrinterSettings.PrinterName = objPrinter.Value.ToString();
cr1.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize;
CrystalDecisions.Shared.PageMargins margins = new CrystalDecisions.Shared.PageMargins(0, 0, 0, 0);
cr1.PrintOptions.ApplyPageMargins(margins);
crystalReportViewer1.ReportSource = cr1;
cr1.PrintToPrinter(1, false, 0, 0); //and here i get the error!
Can someone help me out? I really have no idea what to do.
Mitja
I have a C# .NET WinForms application that uses Crystal Reports.
Crystal reports run fine on both x32 and x64 systems with the exception of reports containing subreports. Any report containing a subreport fails with the wonderful: "Log on failed" at ...VerifyDatabase() but only on x64 systems.
I have seen and fixed this problem in the past by unchecking Verify Database on every print, making sure the no data is being saved with the report and ensuring the correct driver and connection methods are being used in the designer. This problem is not going away and seems to only be affecting reports with subreports.
All projects in the solution are set to build to x32.
The x64 systems have the CR 32bit runtime installed.
The SQL Native Client is also installed.
I have tried many different combinations of report preparations steps like not verifying the database, not refreshing the report, verifying and not refreshing, refreshing and not verifying... it goes on and on.
Here is the current preparation method being used:
private T GetReport<T>() where T: ReportDocument, new()
{
var report = new T();
var connectionStringBuilder
= new SqlConnectionStringBuilder(this.ConnectionString);
var connectionInfo = new ConnectionInfo
{
DatabaseName = connectionStringBuilder.InitialCatalog,
UserID = connectionStringBuilder.UserID,
Password = connectionStringBuilder.Password,
ServerName = connectionStringBuilder.DataSource
};
Action<ReportDocument, bool, bool> setConnection = (document, verify, refresh) =>
{
document.DataSourceConnections.Clear();
document.DataSourceConnections[0].SetConnection(
connectionStringBuilder.DataSource,
connectionStringBuilder.InitialCatalog,
connectionStringBuilder.UserID,
connectionStringBuilder.Password
);
document.DataSourceConnections[0].IntegratedSecurity = false;
/*
foreach (Table table in document.Database.Tables)
{
var tableLogOnInfo = table.LogOnInfo;
tableLogOnInfo.ConnectionInfo = connectionInfo;
table.ApplyLogOnInfo(tableLogOnInfo);
}
* */
//document.SetDatabaseLogon(connectionInfo.UserID, connectionInfo.Password, connectionInfo.ServerName, connectionInfo.DatabaseName);
if (verify)
document.VerifyDatabase();
if (refresh)
document.Refresh();
};
for (var index = 0; index < report.Subreports.Count; index++)
{
var subreportName = report.Subreports[index].Name;
var subreport = report.OpenSubreport(subreportName);
setConnection(subreport, false, false);
}
setConnection(report, true, true);
return report;
}
SOLVED: I have gotten the report to work. I am not sure what part of this solution actually solved the problem but these are the steps I took.
I checked the data source per aMazing's suggestion below. (It was already OLE DB)
I removed all referenced to Crystal Reports in all projects in the solution.
I re-added the Crystal Reports references and made sure all the references were the same version and made sure all references were set to 'Specific Version' = True.
I set 'Copy Local' to True on the CR references on one project in the solution.
I changed the call to the **setConnection** to not verify.
I un-commented foreach table.ApplyLogOnInfo(tableLogOnInfo) section.
I'm not sure why it works now but it does. The table.ApplyLogOnInfo was un-commented in many of the permutations I tried earlier. Maybe I never hit this specific combination... but I don't care at this point.
SOLVED: I have gotten the report to work. I am not sure what part of this solution actually solved the problem but these are the steps I took.
I checked the data source per aMazing's suggestion below. (It was already OLE DB)
I removed all referenced to Crystal Reports in all projects in the solution.
I re-added the Crystal Reports references and made sure all the references were the same version and made sure all references were set to 'Specific Version' = True.
I set 'Copy Local' to True on the CR references on one project in the solution.
I changed the call to the **setConnection** to not verify.
I un-commented foreach table.ApplyLogOnInfo(tableLogOnInfo) section.
I'm not sure why it works now but it does. The table.ApplyLogOnInfo was un-commented in many of the permutations I tried earlier. Maybe I never hit this specific combination... but I don't care at this point.
Because I couldnt add a comment, this was the only way I could reply.
What SQL server are you using? I had something similar before.
Check the following on both report and sub report:
1) Right Click Datasource Properties
2) Select Set Datasource Location
3) On the connetion that the report is using, click expand Properties
4) Confirm that the Database Type = OLE DB (ADO) and Provider is SQLOLEDB.
That fixed my problem. I had set it to SQLNative Client before which was failing.
Hope it helps.
Thanks
Check if you have an Access database or any other 32 bit datasource in any of the subreports.
I had this same problem recently. I found the cause to be not setting the datasource, which in my case was due to an incorrect if statement, meaning the following line was not running:
repdoc.Subreports["SubReportName.rpt"].SetDataSource((DataTable)MyDataTable);
Hope this is of use.