简体   繁体   中英

Access Reporting Services Export using WebClient when the report has parameters

I've come accross a problem when trying to use WebClient to export a report from Reporting Services.

Everything works fine if I use my code to load a report that doesn't contain any parameters, once I try to pass parameters I am getting a 500 Server Error.

If I hit the Reporting Services URL in a web browser the report loads fine and it takes the parameter values specified in the querystring and returns the report in Excel format.

This is something i've done in the past, so really stumped as to what the problem is. Below is some of the code i'm using, as said this works fine with a report that doesn't have parameters. This is not final code by any means but I need to get it working with parameters first

string url = "http://localhost/Reportserver?/ReportsFolder%2fTheReport&rs:Format=EXCEL&rs:Command=Render&Start=15-01-2013&End=15-01-2013";

WebClient c = new WebClient();
c.UseDefaultCredentials = true;
c.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
byte[] data = c.DownloadData(url);

The fact it works fine when opening the link in the web browser it stumping me, and this issue only occurs with reports that have parameters.

UPDATE

I've just realised where was going wrong, it was the format of dates. I was entering a UK formatted date dd/mm/yyyy (15-01/2013)

It's still a strange one thought because providing it in the UK format works fine when pasting the URL into the web browser.

When supplying a UK date using the WebClient code above, I get the error. I'm not sure why it would be different using either method, no longer a problem for me, but still would be interested to know why this is so...

Ensure that the date is sent in the format of mm/dd/yyyy when sending the request via WebClient.

It appears that even if the UK date format dd/mm/yyyy works in IE, it does not when making the request via WebClient and the code in the original question.

The reverse appears to be true in my case that when pasting the URL into IE an error will be thrown if the date is provided in the US format of mm/dd/yyyy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM