I'm generating a lot of reports using the ReportProcessor class and the RenderReport function to get the PDF and save it in a share drive.
private byte[] GetReport(int param)
{
var reportProcessor = new ReportProcessor();
var reportSource = new UriReportSource
{
Uri = Path.Combine(_environment.ContentRootPath, "Reports", "Report.trdp"),
};
reportSource.Parameters.Add(new Parameter("param", param));
var result = reportProcessor.RenderReport("PDF", reportSource, new Hashtable());
return result.DocumentBytes;
}
This works fine. But if I only run the application and get to generate the reports I get:
"An error has occurred while processing Report 'Report':
Unable to establish a connection to the database. Please verify that your connection string is valid. In case you use a named connection string from the application configuration file, make sure the name
is correct and the connection string settings are present in the configuration file of your application.
------------- InnerException -------------
Format of the initialization string does not conform to specification starting at index 0."
The part that I don't understand is that if I go to the page where I have a HTML5 Report Viewer and generate and view a report from the page the error goes away.
I search a lot about this and tried different things and got nothing.
The problem might be related with the appsettings.
We have different configuration for each env and the appsettings.json is merged with appsettings.ENV.json
I tried to put the con string in the base appsettings and worked fine.
I need a solution because I still need to have diferent connectionstrings in different enviorments and I can't reliable run the report in the viewer before generate the standalone PDF
private byte[] GetReport(int param)
{
var reportProcessor = new ReportProcessor();
var reportSource = new UriReportSource
{
Uri = Path.Combine(_environment.ContentRootPath, "Reports", "Report.trdp"),
};
reportSource.Parameters.Add(new Parameter("param", param));
var result = reportProcessor.RenderReport("PDF", reportSource, new Hashtable());
return result.DocumentBytes;
}
This works fine. But if I only run the application and get to generate the reports I get:
"An error has occurred while processing Report 'Report':
Unable to establish a connection to the database. Please verify that your connection string is valid. In case you use a named connection string from the application configuration file, make sure the name
is correct and the connection string settings are present in the configuration file of your application.
------------- InnerException -------------
Format of the initialization string does not conform to specification starting at index 0."
The part that I don't understand is that if I go to the page where I have a HTML5 Report Viewer and generate and view a report from the page the error goes away.
I search a lot about this and tried different things and got nothing.
The problem might be related with the appsettings.
We have different configuration for each env and the appsettings.json is merged with appsettings.ENV.json
I tried to put the con string in the base appsettings and worked fine.
I need a solution because I still need to have diferent connectionstrings in different enviorments and I can't reliable run the report in the viewer before generate the standalone PDF