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

XML Defination with programatic DataSource

5 Answers 43 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jody Harbour
Top achievements
Rank 1
Jody Harbour asked on 16 Jul 2013, 06:36 AM
I have designed a report that I need to programmatically set the connection string

my report viewer code is
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
             Try
                 If Not IsPostBack Then
                    Dim uriReportSource As New Telerik.Reporting.UriReportSource()
                     Dim r As reportObj = daoFactory.GetreportObjDao.GetById(New Guid(Request.QueryString("ID")), False)
                     Dim path As String = System.Web.HttpRuntime.AppDomainAppPath + "Temp\"
                     path += ClientID.ToString() + "\" + r.FileName
                     uriReportSource.Uri = path
                    Me.trv.ReportSource = uriReportSource
                End If 
            Catch ex As Exception
                error(ex) 
            End Try
        End Sub



Here is my data source deceleration from the XML file:
<DataSources>
  <SqlDataSource ConnectionString="hippo" SelectCommand="select top 1 fl.license, f.*, a.* from t_facility_license fl inner join t_facility f on f.facilitylicenseguid = fl.facilitylicenseguid outer apply ( select top 1 * from t_address where foreignkeyguid = f.facilityguid and addresstype = 'Physical' ) a where fl.facilitylicenseguid = @FacilityLicenseGuid order by f.createdate" Name="FacilityLicense">
 
  </SqlDataSource>
</DataSources>

How do I programmatically set the connection string "hippo"?

Thanks!

5 Answers, 1 is accepted

Sort by
0
Squall
Top achievements
Rank 1
answered on 17 Jul 2013, 12:53 PM
0
Jody Harbour
Top achievements
Rank 1
answered on 17 Jul 2013, 02:44 PM
So what your telling me is I have to do something on every report? Add a User Function and hidden parameter to pass in the connection string.

Seems like pretty simple functionality if I could just set the shared datasource on the viewer VIA code instead of the config file.

Please don't tell me this is the only option, as I have been looking around and a lot of people seem to be complaining about this.

I think I you just added a setter off the Telerik.Reporting.UriReportSource.SetConnectionString("Hippo","connection string value") that it would solve a many of complaints.
0
Stef
Telerik team
answered on 22 Jul 2013, 03:02 PM
Hi Jody,

You can use named connection strings and change the target server by changing the connection in the configuration file. Other approach is to deserialize the report definition and iterate through the report's Items collection to get all SqlDataSource components set as DataSource, and then modify their settings.

I hope this helps.

Regards,
Stef
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

0
Jody Harbour
Top achievements
Rank 1
answered on 29 Sep 2013, 12:39 AM
I was provided with this example code which works if you only have one datasource on the report
Dim settings As New XmlReaderSettings()
settings.IgnoreWhitespace = True
 Using xmlReader As System.Xml.XmlReader = System.Xml.XmlReader.Create("Report1.xml", settings)
    Dim xmlSerializer As New Telerik.Reporting.XmlSerialization.ReportXmlSerializer()
     Dim report As Telerik.Reporting.Report = DirectCast(xmlSerializer.Deserialize(xmlReader), Telerik.Reporting.Report)
    Dim ds As Telerik.Reporting.SqlDataSource = DirectCast(report.DataSource, Telerik.Reporting.SqlDataSource)
    'change data source as desired
End Using

I noticed that of the report object there is a datasources property that is marked as friend so I cant access it directly to loop through the other datasources and set them as well. Do you have any ways that I can get access to the other datasources to set their connection strings as well?
0
Stef
Telerik team
answered on 30 Sep 2013, 03:40 PM
Hello Jody,

This is a quote from your support ticket on the same question:

"To change the inner items assigned data sources, you will have to iterate the report's Items collection and get the items having individual DataSource - Chart, Graph, Table/List/Crosstab items and parameters' AvailableValues."

Regards,
Stef
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

Tags
General Discussions
Asked by
Jody Harbour
Top achievements
Rank 1
Answers by
Squall
Top achievements
Rank 1
Jody Harbour
Top achievements
Rank 1
Stef
Telerik team
Share this question
or