Page 1 of 1

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

Posted: Mon Mar 04, 2019 6:17 pm
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.

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

Posted: Mon Mar 04, 2019 8:50 pm
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.

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

Posted: Wed Mar 06, 2019 10:29 am
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.

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

Posted: Wed Mar 06, 2019 7:53 pm
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.