Currently running version R1 2020 SP1 (14.0.20.219) with the HTML 5 report viewer and the REST service ASP.NET Core 3.1
I am trying to set the database connection string dynamically using the method outlined in the knowledge base article below which passes it as a report parameter.
Change Connection String dynamically through a report parameter
This approach should be fine, however the issue is that I cannot find a way to modify the report parameters so that the connection string can be passed in.
I have tried to define a custom report resolver like the example below which adds the parameter to the report source. But I am finding that the parameter value does not get passed into the report.
We are using .trdp files as our report source and I have seen some examples where people have unpacked the file to return an InstanceReportSource. By doing this it might be possible to set the parameters against the report object directly.
Can anyone suggest a better way to set report parameters within the REST service (ie without passing the parameters from the client)?
Thanks
Andrew
public
class
CustomReportResolver : ReportFileResolver
{
private
readonly
IDdrConnectionService _ddr;
private
readonly
IHttpContextAccessor _httpContextAccessor;
public
CustomReportResolver(IDdrConnectionService ddr,
IHttpContextAccessor httpContextAccessor,
string
repositoryDirectory) :
base
(repositoryDirectory)
{
_ddr = ddr;
_httpContextAccessor = httpContextAccessor;
}
protected
override
ReportSource ResolveReport(
string
report)
{
ReportSource reportSource =
base
.ResolveReport(report);
Guid tenantId = _httpContextAccessor.HttpContext.User.GetTenantId();
string
connString = _ddr.GetShardConnectionString(tenantId);
reportSource.Parameters.Add(
"ConnectionString"
, connString);
return
reportSource;
}
}