How to get data source information from SSRS report using .NET.

I am currently creating an ASP.Net and C # page, which is an interface for some reports.

I also want to run some queries from the same data source as the reports (each report uses only one data source).

Is it possible to extract information from a data source from a report using ReportingService2005 or ReportExecutionService elements so that they can be reused in SqlConnection?

+4
source share
2 answers

You can use the ReportingService2005 API to get the data source used by a particular report.

You need the full report path (which I assume you have), and then use it to query the reporting service for your data source ( API ).

// rs = ReportingService2005 that you need to set up. DataSource ds; DataSources dataSources = rs.GetItemDataSources(item); // item is a string containing the full path to the report. dataSources = rs.GetItemDataSources(item); ds = dataSources[0]; 

The ds in the above code is either a DataSourceDefinition or a DataSourceReference . If this is a definition, you can simply enter it into this type and then get the connection string using the following code.

 DataSourceDefinition dsd = ds as DataSourceDefinition(); if(dsd == null) throw new Exception(); String connectionString = dsd.ConnectString; 

If this is a quality definition, you need to check the API .

+3
source

Hope this helps. It will display all the properties, but in particular it will pull out the connection string:

 using System; using GetPropertiesSample.ReportService2010; //This is the WebService Proxy using System.Diagnostics; using System.Reflection; using System.Web.Services.Protocols; using System.IO; namespace GetPropertiesSample { class Program { static void Main(string[] args) { Get_Properties_of_DataSource_given_The_Path_and_Name_of_the_Report(); } private static void Get_Properties_of_DataSource_given_The_Path_and_Name_of_the_Report() { try { // Create a Web service proxy object and set credentials ReportingService2010 rs = new ReportingService2010(); rs.Credentials = System.Net.CredentialCache.DefaultCredentials; string reportPathAndName = "/0_Contacts/209_Employee_Telephone_List_Printable"; DataSource[] dataSources = rs.GetItemDataSources(reportPathAndName); DataSource ds = dataSources[0]; string dsName = ds.Name; Debug.Print("----------------------------------------------------"); Debug.Print("Data Source Name: " + dsName); Debug.Print("----------------------------------------------------"); DataSourceDefinition dsd = (DataSourceDefinition)ds.Item; if (dsd != null) { //Here is one property string connectionString = dsd.ConnectString; // <====== HERE is the Connection Strin //Use Reflection to get all the properties : using System.Reflection; var typeDSD = typeof(DataSourceDefinition); var properties = typeDSD.GetProperties(); foreach (PropertyInfo p in properties) { Debug.Print("----------------------------------------------------"); Debug.Print(p.Name + ": " + p.GetValue(dsd, null)); } } } catch (SoapException e) { Debug.Print("=============================="); Debug.Print(e.Detail.OuterXml); Debug.Print("=============================="); } catch (Exception e) { Debug.Print("=============================="); Debug.Print(e.Message); Debug.Print(e.InnerException.ToString()); Debug.Print(e.ToString()); Debug.Print("=============================="); } } } 
0
source

All Articles