Change connection string in code asp.net core mvc - not working

Stimulsoft Reports.NET discussion
Post Reply
xnetdude
Posts: 7
Joined: Sat Feb 23, 2019 11:38 am

Change connection string in code asp.net core mvc - not working

Post by xnetdude »

Hi - like many we need to change the connection string from dev environment to production.

We have looked at all the articles here are believe we only need to do this after the "Report" is loaded :-

Code: Select all

report.Load(...);
connectionString = "Data Source=SQLSERVERNAME;Initial Catalog=LotsOfLovelyData;Integrated Security=False;User ID=sa;Password=shhhSecret";
report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("LotsOfLovelyData", connectionString));
But the reports are blank! We have tried using this technique for exactly the same connection string we are using with the Report Builder, with same blank results.

If we don't use any of the above code, the reports work fine in the dev environment.

Please could someone assist.

Thanks.
Lech Kulikowski
Posts: 6247
Joined: Tue Mar 20, 2018 5:34 am

Re: Change connection string in code asp.net core mvc - not working

Post by Lech Kulikowski »

Hello,

Please check that NameInSource property of data sources is "LotsOfLovelyData".
Also, you can use the following code:

Code: Select all

((StiSqlDatabase)report.Dictionary.Databases[ "DataBaseName"]).ConnectionString = connectionString;
Thank you.
xnetdude
Posts: 7
Joined: Sat Feb 23, 2019 11:38 am

Re: Change connection string in code asp.net core mvc - not working

Post by xnetdude »

Lech - I assume your solution would not work in the scenario of ...Databases.Clear(); as there would be no entry to reference as per your example.

I've seen lots of different posts suggesting what should or shouldnt be cleared and assigned. Could you post all the lines required please as a complete method so I can get some clarity surrounding this. Please assume everything remains the same apart from the connection string.

Thanks.
Lech Kulikowski
Posts: 6247
Joined: Tue Mar 20, 2018 5:34 am

Re: Change connection string in code asp.net core mvc - not working

Post by Lech Kulikowski »

Hello,

You can change exists connection string:

Code: Select all

connectionString = "Data Source=SQLSERVERNAME;Initial Catalog=LotsOfLovelyData;Integrated Security=False;User ID=sa;Password=shhhSecret";
report.Load(...);
((StiSqlDatabase)report.Dictionary.Databases[ "DataBaseName"]).ConnectionString = connectionString;
or clear and add new:

Code: Select all

report.Load(...);
connectionString = "Data Source=SQLSERVERNAME;Initial Catalog=LotsOfLovelyData;Integrated Security=False;User ID=sa;Password=shhhSecret";
report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("NAME SHOULD BE SAME AS IN LOAD REPORT", connectionString));
If the issue still present, please send us a sample which reproduces the issue for analysis.

Thank you.
Post Reply