Change SQL connection dynamically (data sources)

Stimulsoft Reports.NET discussion
Post Reply
mellorafael
Posts: 10
Joined: Wed Oct 30, 2013 3:52 pm

Change SQL connection dynamically (data sources)

Post 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
Attachments
sqlconn.jpg
sqlconn.jpg (111.13 KiB) Viewed 1613 times
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Change SQL connection dynamically (data sources)

Post 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.
mellorafael
Posts: 10
Joined: Wed Oct 30, 2013 3:52 pm

Re: Change SQL connection dynamically (data sources)

Post by mellorafael »

Thank you Aleksey, your code works fine!

best regards
Rafael Mello
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: Change SQL connection dynamically (data sources)

Post by Alex K. »

Hello,

We are always glad to help you!
Post Reply