Page 1 of 1

Change SQL connection dynamically (data sources)

Posted: Wed Jan 15, 2014 10:22 am
by mellorafael
Hi,

I want to change the SQL Connection (that is already exists in the mrt file) dynamically by .Net code.

I tried:

report.Dictionary.DataSources.Clear();
report.Dictionary.DataSources.Add(new StiSqlSource("DBConnection", hhh.ConexaoAtiva.ConnectionString));



But not work.

Could you help-me?

Thanks
Rafael Mello

Re: Change SQL connection dynamically (data sources)

Posted: Wed Jan 15, 2014 10:28 am
by Alex K.
Hello,

Please try to use the following code:

Code: Select all

((StiSqlDatabase)report.Dictionary.Databases["DBConnection"]).ConnectionString = hhh.ConexaoAtiva.ConnectionString);
or

Code: Select all

report.Dictionary.Databases.Clear();
report.Dictionary.Databases.Add(new Stimulsoft.Report.Dictionary.StiSqlDatabase("DBConnection", hhh.ConexaoAtiva.ConnectionString));
Thank you.

Re: Change SQL connection dynamically (data sources)

Posted: Wed Jan 15, 2014 11:02 am
by mellorafael
Thank you Aleksey, your code works fine!

best regards
Rafael Mello

Re: Change SQL connection dynamically (data sources)

Posted: Wed Jan 15, 2014 11:10 am
by Alex K.
Hello,

We are always glad to help you!