This is a migrated thread and some comments may be shown as answers.

sqlDataSource wizard sets ConnectionString to a String of the Settings Variable, not a reference.

3 Answers 971 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 1
Brad asked on 07 Sep 2011, 12:38 AM
I am setting up a Telerik Reporting Class Library in a WinForms Solution, with Telerik Reporting Q2 2011. Following the Best Practices, I am using a sqlDataSource, and have used the wizard to setup the connection and SQL statements.

The problem is that the report editor has set the connection string in the report designer file like so:

Report1.Designer.cs
this.sqlDataSource1.ConnectionString = "ReportsProject.Properties.Settings.ReportsConnectionString";

It is a String of the Report Project Settings Variable, not a Reference to the Report Project Settings Variable. This works fine for designing the report within the Reports Project, however, a ReportViewer in a Forms Project will produce a run-time error.

Error Output Produced:
  • Telerik.Reporting.Processing.Data.SqlDataSourceException: Unable to establish a connection to the database. Please, verify that your connection string is valid. In case you use a named connection string from the application configuration file, make sure the name is correct and the connection string settings are present in the configuration file of your application. ---> System.ArgumentException: Format of the initialization string does not conform to specification starting at index 0.

I have attempted to rectify the error by copying the Connection String Setting from the Report Project into the Forms Project. I assume this doesn't work as the Connection String is trying to reference the Private Connection String in the Report Project.

I now set the Connection String in the Report Constructor to the Settings Value. After this is added the Forms Project displays the report without error.

Report1.cs
this.sqlDataSource1.ConnectionString = ReportsProject.Properties.Settings.Default.ReportsConnectionString;

 I am unsure why I am required to reference the setting through the "Settings.Default" object, where the designer sets a string that references straight from the "Settings" object. (edit: the report reads the app.config file, it doesn't use the settings object)

Is there a work around so I won't need to set the connection string in the constructor as well as the designer? 

3 Answers, 1 is accepted

Sort by
0
Brad
Top achievements
Rank 1
answered on 07 Sep 2011, 04:53 PM
I have figured out the where to place the connection string in a Solution's Report Project and Form Project. I tried entering the Report's connection string into the Form Project's Properties and Settings tab. The reports are unable to use a connection string entered like this, as they are reading the Form Project's app.config file directly, not accessing it through the Settings object. To provide the correct connection string, copy the XML entry from the Report Project's app.config file, to the Form Project's app.config file.

Form Project: app.config
<connectionStrings>   
<add name="ReportsProject.Properties.Settings.ReportsConnectionString"
        connectionString="Data Source=(local)\SQLEXPRESS;Initial Catalog=Main_DB;Integrated Security=True"
        providerName="System.Data.SqlClient" />
</connectionStrings>

Remember to change the both project's connection string when it needs to be updated.
0
Massimiliano Bassili
Top achievements
Rank 1
answered on 08 Sep 2011, 01:36 PM
Correct, description on why this is necessary is available in a reporting KB article: 

Using connectionStrings from configuration file

0
Engineering
Top achievements
Rank 1
answered on 27 Oct 2011, 06:52 PM
FYI, The "Using connectionStrings from configuration file" link is broken. 

 I have a similar problem. I downloaded the Telerik Reporting trial version, wrote a bunch of reports, then bought the real version. The real version won't recognize my existing connection string names and insists on using a "Project.Properties.Settings.DataBase" naming convention that doesn't work for me.  I don't want different connection string names for the same connection and my app already has many references to the existing connection strings. Other than code changes, is there some way around this?
Tags
General Discussions
Asked by
Brad
Top achievements
Rank 1
Answers by
Brad
Top achievements
Rank 1
Massimiliano Bassili
Top achievements
Rank 1
Engineering
Top achievements
Rank 1
Share this question
or