OnInitReportOptions() has been modified from the examples I found with my own datasource and datasourcecredentials. I also set it to a local processing.
public partial class IncidentsController : Controller, IReportController
{
private IMemoryCache _cache;
private IHostingEnvironment _hostingEnvironment;
public IncidentsController(IMemoryCache memoryCache, IHostingEnvironment hostingEnvironment)
{
_cache = memoryCache;
_hostingEnvironment = hostingEnvironment;
}
public ActionResult Index()
{
return View();
}
public IActionResult Error()
{
return View();
}
[HttpPost]
public object PostReportAction([FromBody] Dictionary<string, object> jsonResult)
{
if (jsonResult.ContainsKey("CustomData"))
{
var paramValue = jsonResult["CustomData"];
}
return ReportHelper.ProcessReport(jsonResult, this, this._cache);
}
[ActionName("GetResource")]
[AcceptVerbs("GET")]
public object GetResource(ReportResource resource)
{
return ReportHelper.GetResource(resource, this, _cache);
}
[HttpPost]
public object PostFormReportAction()
{
return ReportHelper.ProcessReport(null, this, this._cache);
}
public void OnInitReportOptions(ReportViewerOptions reportOption)
{
string basePath = _hostingEnvironment.WebRootPath;
FileStream inputStream = new FileStream(basePath + @"\Incidents.rdlc", FileMode.Open, FileAccess.Read);
reportOption.ReportModel.Stream = inputStream;
//DataSet ds = new DataSet();
//ds = Loadds();
OdbcConnection connection = new OdbcConnection("Driver={ODBC Driver 17 for SQL Server}; Server=localhost\\SQLEXPRESS;Database=GirlsHaven;Trusted_Connection=Yes;MultipleActiveResultSets=true;ColumnEncryption=Enabled;App=dataset;");
var strsql = "SELECT * from qryIncidents";
OdbcDataAdapter adapter = new OdbcDataAdapter(strsql, connection);
DataSet ds = new DataSet();
adapter.Fill(ds);
reportOption.ReportModel.DataSources.Clear();
reportOption.ReportModel.DataSources.Add(new ReportDataSource { Name = "DataSet1", Value = ds.Tables[0] });
DataSourceCredentials dsc = new DataSourceCredentials();
dsc.ConnectionString = "Driver={ODBC Driver 17 for SQL Server}; Server=localhost\\SQLEXPRESS;Database=GirlsHaven;MultipleActiveResultSets=true;ColumnEncryption=Enabled;app=reportdatasource;";
dsc.IntegratedSecurity = false;
dsc.UserId = "*******";
dsc.Password = "*******";
dsc.Name = "GirlsHaven";
reportOption.ReportModel.DataSourceCredentials.Add(dsc);
reportOption.ReportModel.ProcessingMode = ProcessingMode.Local;
}
public void OnReportLoaded(ReportViewerOptions reportOption)
{
}
}