Arjay
April 2nd, 2007, 07:40 PM
Our clients are using SQL 2005 Report builder to generate queries based on the data model we've supplied (the env is Sql 2005 and VS 2005, .Net 2.0).
The client is quite happy that they can create the report and we can programmically display the report using the report viewer in Asp.Net. Everyone is happy, almost.
What we want to do is to take the report they've created, dis-assemble it and use the query (or filter) from the rdl to perform some other database operations using the filter portion of the query.
I know I can retrieve the rdl and load it up into the Reports class (created by running xsd on ReportDefinition.xsd) as follows:
privatestaticvoid LoadReportDefinition( )
{
ReportingService2005 rs = newReportingService2005( );
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
string reportPath = "/EmployeeReport";
// Retrieve the report definition from the report server
byte[ ] bytes = rs.GetReportDefinition( reportPath );
Report report = null;
if( bytes != null )
{
XmlSerializer serializer = newXmlSerializer( typeof( Report ) );
// Load the report bytes into a memory stream
using( MemoryStream stream = newMemoryStream( bytes ) )
{
// Deserialize the report stream to an instance of the Report class
report = ( Report ) serializer.Deserialize( stream );
}
}
}
From there I can drill down and retrieve the CommandText which contains the filter.
What I'm looking to do is take that filter command and convert it back into the sql query that I can run against the db.
Is there a way to do this programmatically or do I have to derive it on my own based on the filter elements?
The client is quite happy that they can create the report and we can programmically display the report using the report viewer in Asp.Net. Everyone is happy, almost.
What we want to do is to take the report they've created, dis-assemble it and use the query (or filter) from the rdl to perform some other database operations using the filter portion of the query.
I know I can retrieve the rdl and load it up into the Reports class (created by running xsd on ReportDefinition.xsd) as follows:
privatestaticvoid LoadReportDefinition( )
{
ReportingService2005 rs = newReportingService2005( );
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
string reportPath = "/EmployeeReport";
// Retrieve the report definition from the report server
byte[ ] bytes = rs.GetReportDefinition( reportPath );
Report report = null;
if( bytes != null )
{
XmlSerializer serializer = newXmlSerializer( typeof( Report ) );
// Load the report bytes into a memory stream
using( MemoryStream stream = newMemoryStream( bytes ) )
{
// Deserialize the report stream to an instance of the Report class
report = ( Report ) serializer.Deserialize( stream );
}
}
}
From there I can drill down and retrieve the CommandText which contains the filter.
What I'm looking to do is take that filter command and convert it back into the sql query that I can run against the db.
Is there a way to do this programmatically or do I have to derive it on my own based on the filter elements?