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

Setting connection string for all sqldatasources

5 Answers 106 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
DuelingCats
Top achievements
Rank 2
DuelingCats asked on 28 Mar 2017, 06:21 PM

I have a report that has several SqlDataSources. Viewing the Report XML, the markup looks like the following:

<?xml version="1.0" encoding="utf-8"?>
<Report DataSourceName="This is my report" Width="10.0000012715658in" Name="Detailed Report" xmlns="http://schemas.telerik.com/reporting/2012/4.2">
  <DataSources>
    <SqlDataSource QueryDesignerState="null" ConnectionString="connection_string_here" ProviderName="System.Data.OracleClient" SelectCommand="select statement goes here" Name="a name goes here1">
      <Parameters>
        <SqlDataSourceParameter DbType="String" Name="Work_Week" />
        <SqlDataSourceParameter DbType="String" Name="name" />
      </Parameters>
    </SqlDataSource>
    <SqlDataSource QueryDesignerState="null" ConnectionString="connection_string_here" ProviderName="System.Data.OracleClient" SelectCommand="select statement goes here" Name="a name goes here2" />
    <SqlDataSource QueryDesignerState="null" ConnectionString="connection_string_here" ProviderName="System.Data.OracleClient" SelectCommand="select statement goes here" Name="a name goes here3" />
  </DataSources>
  <Items>
  </Items>
  <PageSettings PaperKind="Letter" Landscape="True" ColumnCount="1" ColumnSpacing="0in" ContinuousPaper="False">
  </PageSettings>
  <StyleSheet>
  <Filters>
  </Filters>
  <Sortings>
  </Sortings>
  <Groups>
  </Groups>
</Report>

 

The problem is when I am try to use this code to change the connection string, it only appears to change the string for the <Report> tag. The 3 SqlDataSources appear to be private members of the object when I look at it while debugging and those connection strings are not modified by the code. I need those modified by code. The only way I have found to do this is to treat the XML as regular XML and replace those node's attributes with the proper strings instead of using the Telerik class properties/methods. This doesn't seem right, so I assume there is a way to set these connection strings properly.

5 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 29 Mar 2017, 03:59 PM
Hello,

Once the report is designed, you need to iterate all data items and report parameters having their DataSource properties set. When you get their DataSource properties you can cast it to the used data source component's type and updated the required settings.

For example, please check Changing the connection string dynamically according to runtime data.

Note that the report in your example is empty. To test the setting for changing connection strings, test creating a report with data items e.g. How To: Create a Report (Standalone Report Designer).

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
DuelingCats
Top achievements
Rank 2
answered on 29 Mar 2017, 04:18 PM
I was using that example you linked and it was not setting the connection string on all my sqldatasources like I said beforehand.
0
Stef
Telerik team
answered on 29 Mar 2017, 04:49 PM
Hello,

There is no direct access to data source components. Even changing a data source component settings, they will not be propagated to the items which use that data source component.

You need to iterate the data items and to modify each DataSource property separately.


Feel free to log a feature request for having an unified access to the report's DataSources. Features are considered for implementation based on the demand.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
DuelingCats
Top achievements
Rank 2
answered on 29 Mar 2017, 04:59 PM
When running the code linked beforehand, I placed breakpoints in SetConnectionString. I see that the connection string is only set one time when it should be setting 4 different SqlSataSource elements from what I can understand. Is it because of how my report is formatted? I opened a support ticket that has the XML in full as I did not want to publish it here.
0
Stef
Telerik team
answered on 30 Mar 2017, 02:27 PM
Hi,

I am posting a quote with the general information from my response in your support ticket on the same question.

"The Standalone Report Designer can save TRDP files as TRDX allowing you to get the content in readable XML via text editor like Notepad. You need to use Standalone Report Designer - File - Save As - Save As Type:TRDX option.

About the reported problem:
  1. When you design a report you can add data source components like SqlDataSource in the report. All data source components are private and cannot be accessed through the report instance at run-time.
  2. When you run the code to modify the connection strings in the report, the code iterates all elements of the report's Items collection recursively. Each found data item, that has its DataSource set, will be updated to use the new connection string.
    Note that these changes are not applied on the SqlDataSource components, the changes are applied on the specific item's DataSource property that can be cast to a SqlDataSource."

Please note that there are several unused data source components in the report. Data items pick the settings only of the data source components assigned as their DataSource.

Regards,
Stef
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
DuelingCats
Top achievements
Rank 2
Answers by
Stef
Telerik team
DuelingCats
Top achievements
Rank 2
Share this question
or