views:

985

answers:

1

I am currently making an ASP.Net and C# page, which is a front end for some reports.

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

Is it possible to extract the data source connection information from a report, using either ReportingService2005 or ReportExecutionService members, so that it can be reused in an SqlConnection?

+1  A: 

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

You need the full path of the report (which I assume you have), and then use it to query the reporting service for its 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 code above is either a DataSourceDefinition or a DataSourceReference. If it's a definition you can just cast it into that 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 it's a datasourcereference you need to check out the API.

Mats Fredriksson
VB's a bit rusty? The OP specified C# as the language they are using
csjohnst
The VB code was enough for me to get it working in C#, it does exactly what I want - Thank you :)
Sophia
@csjohnst: Now that you mention it.. :) The script I was doing this in was in VB so I got confused..
Mats Fredriksson