Hello All,
I wanted to post this so no one else has to go through what I went through trying to figure out how to dynamically change the connection string when using .trdx files as the urisource in the windows forms report viewer and having each customer with their own database being able to run the canned reports that we make for our software.
First, when you design the report, give the SQL Datasource a Name and check the box to save it in the configuration file (I did this from the Telerik Standalone Report Designer. This will not expose your connection information to end users and allow them to create alternative reports for your canned reports without letting them see the connection password.
Second, add a line into your [appname].exe.config file for the connection string and leave the connection string value BLANK. It should look something like this (put this right under <configSections> and I think the casing matters on <connectionStrings>:
<connectionStrings>
<add name="Marketplace" providerName="System.Data.SqlClient" connectionString="" />
</connectionStrings>
Next, if you have a connection string either encrypted (we encrypt our connection password only and read it into memory on login to our application and assign it to a global variable called ADOnet), you will want to set the named connectionstring in memory and have it refresh. In VB.Net, this can be done by using the following code:
Dim config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
Dim connectionStringsSection = DirectCast(config.GetSection("connectionStrings"), ConnectionStringsSection)
connectionStringsSection.ConnectionStrings("Marketplace").ConnectionString = ADONet
config.Save()
ConfigurationManager.RefreshSection("connectionStrings")
In order to get ConfigurationManager to show up under System.Configuration you need to add System.Configuration explictily to your references in your project (just imports or using will not give you configuration manager)
Anyway, this will update your settings for your named connection in your reports in memory while in runtime.
Hope this helps you to not spend the 5 hours of research and testing it took me to find this solution.
Philip Carter
http://emanageone.com
I wanted to post this so no one else has to go through what I went through trying to figure out how to dynamically change the connection string when using .trdx files as the urisource in the windows forms report viewer and having each customer with their own database being able to run the canned reports that we make for our software.
First, when you design the report, give the SQL Datasource a Name and check the box to save it in the configuration file (I did this from the Telerik Standalone Report Designer. This will not expose your connection information to end users and allow them to create alternative reports for your canned reports without letting them see the connection password.
Second, add a line into your [appname].exe.config file for the connection string and leave the connection string value BLANK. It should look something like this (put this right under <configSections> and I think the casing matters on <connectionStrings>:
<connectionStrings>
<add name="Marketplace" providerName="System.Data.SqlClient" connectionString="" />
</connectionStrings>
Next, if you have a connection string either encrypted (we encrypt our connection password only and read it into memory on login to our application and assign it to a global variable called ADOnet), you will want to set the named connectionstring in memory and have it refresh. In VB.Net, this can be done by using the following code:
Dim config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
Dim connectionStringsSection = DirectCast(config.GetSection("connectionStrings"), ConnectionStringsSection)
connectionStringsSection.ConnectionStrings("Marketplace").ConnectionString = ADONet
config.Save()
ConfigurationManager.RefreshSection("connectionStrings")
In order to get ConfigurationManager to show up under System.Configuration you need to add System.Configuration explictily to your references in your project (just imports or using will not give you configuration manager)
Anyway, this will update your settings for your named connection in your reports in memory while in runtime.
Hope this helps you to not spend the 5 hours of research and testing it took me to find this solution.
Philip Carter
http://emanageone.com