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

Setting ConnectionString on the fly via a Telerik.Reporting.Parameter

2 Answers 260 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jean-Pierre
Top achievements
Rank 1
Jean-Pierre asked on 04 May 2020, 03:06 PM

In a cshtml file, I have the following piece of code:

 

                                Telerik.Reporting.UriReportSource uriReportSource = new Telerik.Reporting.UriReportSource();
                                uriReportSource.Uri = "QuotationDetails.trdx";
                                uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("CultureID", "fr"));
                                uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("QuotationIDENT", "{{:CurrentQuotation.IDENT}}"));
                                uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("UNUSED", 15));
                                uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("ReportsConnectionString", "{{:ReportsConnectionString}}"));

 

In th concerned trdx file, the SqlDataSource is currently set via:

  <DataSources>
    <SqlDataSource ConnectionString="REPORTS" SelectCommand="..." Name="REPORTS" ParameterValues="...">
      <Parameters>
        ...
        </SqlDataSourceParameter>
      </Parameters>
    </SqlDataSource>
  </DataSources>

 

I would like to set the SqlDataSource  ConnectionStringvalue to ReportsConnectionString, but I can't make it work.

 

Any idea ?

 

Best Regards,

 

Jean-Pierre Gervasoni

2 Answers, 1 is accepted

Sort by
0
Jean-Pierre
Top achievements
Rank 1
answered on 05 May 2020, 07:04 AM

I was on the right way. The cshtml file did not change, here is the most relevant part of the trdx file - what I was missing was the bindings.

<?xml version="1.0" encoding="utf-8"?>
<Report Width="27.1000020690758cm" Name="QuotationDetails" SnapGridSize="0.1cm" xmlns="http://schemas.telerik.com/reporting/2012/3.8">
  <DataSources>
    <SqlDataSource SelectCommand="..." Name="REPORTS">
      <Parameters>
        ...
      </Parameters>
    </SqlDataSource>
  </DataSources>
  <Items>
    <DetailSection Height="2.5cm" Name="detailSection1">
      <Items>
        <Table DataSourceName="REPORTS" Width="26.7829048452214cm" Height="4.58208139261609cm" Left="0cm" Top="0cm" Name="table1" StyleName="Corporate.TableNormal">
          ...
          <Bindings>
            <Binding Path="DataSource.ConnectionString" Expression="=Parameters.ReportsConnectionString.Value" />
          </Bindings>
        </Table>

      </Items>
    </DetailSection>
    <PageHeaderSection Height="1.09999989906947cm" Name="pageHeaderSection1">
      <Items>
        <TextBox Width="27.1000023718674cm" Height="1.00000010093053cm" Left="0cm" Top="0cm" Value="Détail du Métré" Name="ReportNameTextBox">
          ...
      </Items>
    </PageHeaderSection>
  </Items>
  <StyleSheet>
    ...
  </StyleSheet>
  <PageSettings>
    ...
  </PageSettings>
  <Groups>
    ...
  </Groups>
  <ReportParameters>
    <ReportParameter Name="ReportsConnectionString" Type="String" />
  </ReportParameters>
</Report>

0
Neli
Telerik team
answered on 07 May 2020, 08:54 AM

Hello Jean-Pierre,

The recommended approach for setting the connection string dynamically is described in Change Connection String dynamically through a report parameter KB article.

Then in your .NET MVC application, set the value of the parameter as follows:

uriReportSource.Parameters.Add("ConnectionStringParameter", "ConnectionStringValue");

 

Regards,
Neli
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
General Discussions
Asked by
Jean-Pierre
Top achievements
Rank 1
Answers by
Jean-Pierre
Top achievements
Rank 1
Neli
Telerik team
Share this question
or