Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,


Currently I am using rdlc report with parameters.

From asp.net web app, when I input from and to date and generate report, in my local machine its working fine, but in the production side it is taking long time and report is not comming at all.


My manager says to do the following:

to write a script that works in batch mode, which prepares the report in the background and gives the report in pdf format to the user for a given month.

for this, i need to write a script to generate the report in pdf format for a given month. How can I do this?

Please help me to do this.
Posted

1 solution

Without seeing your code here is a snippet on how to generate SSRS reports in C#

No Idea if this is what you are looking for.

If you could provide more information about what you are trying to achieve then maybe i can improve upon this but for right now this snippet would generate a report from SSRS like you mentioned

C#
//Init Vars
private static string fileName = null;
private static string historyID = null;
private static string deviceInfo = null;
private static string format = "PDF";
private static string encoding = null;
private static string mimeType = null;
private static string extension = null;
private static string[] streamIDs = null;
private static string _reportName = null;
private static string _historyID = null;
private static bool _forRendering = false;
private static Byte[] results;
private static report.Service.Reference reportService;
private static report.Execution.Reference reportExecReference;
//---------------------------------------
//Inside some method, place this code
fileName      = destinationFilePath;
historyID     = null;
deviceInfo    = null;
format        = (Path.GetExtension(destinationFilePath).ToUpper()).Replace(".", "");
encoding      = null;
mimeType      = null;
extension     = null;
streamIDs     = null;
_reportName   = reportName;
_historyID    = null;
_forRendering = false;

reportService = new report.Service.Reference.ReportingService2005();
reportExecReference = new report.Execution.Reference.ReportExecutionService();

reportService.Credentials = new NetworkCredential("username", "password", "DOMAIN");
reportServiceExec.Credentials = new NetworkCredential("username", "password", "DOMAIN");

reportService.Url = String.Format(@"http://{0}/reportserver/reportservice2005.asmx", iniDatabaseServer);
reportServiceExec.Url = String.Format(@"http://{0}/reportserver/reportexecution2005.asmx", iniDatabaseServer);

historyID = null;
deviceInfo = null;
format = Path.GetExtension(destinationFilePath) == ".xls" ? "Excel" : "PDF";
encoding = String.Empty;
mimeType = String.Empty;
extension = String.Empty;
report.Execution.Reference.Warning[] warnings = null;
streamIDs = null;
fileName = destinationFilePath;
_reportName = reportName;
_historyID = null;
_forRendering = false;
report.Service.Reference.ParameterValue[] _values = null;
report.Service.Reference.DataSourceCredentials[] _credentials = null;
report.Service.Reference.ReportParameter[] _parameters = null;
_parameters = reportService.GetReportParameters(_reportName, _historyID, _forRendering, _values, _credentials);
report.Execution.Reference.ExecutionInfo ei = reportServiceExec.LoadReport(_reportName, historyID);
report.Execution.Reference.ParameterValue[] parameters = new report.Execution.Reference.ParameterValue[parameterName.Count];

if (_parameters.Length > 0)
{
    for (int i = 0; i < parameterName.Count; i++)
    {
        //This is where you can either hard code your parameters or pass them in using a List and have it loop through and execute the param name and values for your report.
        parameters[i] = new report.Execution.Reference.ParameterValue();
        parameters[i].Label = null;
        parameters[i].Name = parameterName[i];
        parameters[i].Value = parameterValue[i];
    }
}
reportServiceExec.SetExecutionParameters(parameters, "en-us");

results = reportServiceExec.Render(format, deviceInfo,
          out extension, out encoding,
          out mimeType, out warnings, out streamIDs);

using (FileStream stream = File.OpenWrite(fileName))
{
    stream.Write(results, 0, results.Length);
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900