I am using a WinXP SP2 machine with SQL2000 SP4, and using Reporting
Services SP2 when I get "File not in a recognizeable format" when
rendering to excel. Same goes for trying to render to PDF.
The weird thing is that on a virtual I have with Reporting Services
RTM, the excel opens fine...so I don't know what is going on.
The way I am generating the report is by manually creating a
request/response, adding on the POST vars, and then writing the output
to the browser (changing the content-type to excel, pdf, etc). As I
said, with the RTM version, the excel generates fine, but with SP2 it
doesnt.
Here are the parameters that I am adding onto the URL when I make the
request, along with my custom params.
//SQL REPORTING SERVICES SPECIAL PARAMS
sb.Append("&rs:Command=Render");
sb.Append("&rs:Format=" + exportType);
sb.Append("&rc:Parameters=false");
sb.Append("&rc:Toolbar=false&rs:Encoding=ASCII&rc:NoHeader=true");
I then I generate and return the request with the code below
(GeneratePostData() basically just creates the POST vars from above)
public static string generateReport(string url)
{
String result = "";
//get the data to post.
string postData = GeneratePostData();
System.IO.StreamWriter myWriter = null;
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
objRequest.PreAuthenticate = true;
// Way 1:
//objRequest.Credentials = CredentialCache.DefaultCredentials;
// Way 2:
objRequest.Credentials = new
NetworkCredential(REPORT_USER,REPORT_PASS,REPORT_DOMAIN);
objRequest.Method = "POST";
objRequest.ContentLength = postData.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";
try
{
myWriter = new
System.IO.StreamWriter(objRequest.GetRequestStream());
myWriter.Write(postData);
}
catch (Exception e)
{
return e.Message;
}
finally
{
myWriter.Close();
}
try
{
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
using(System.IO.StreamReader sr = new
System.IO.StreamReader(objResponse.GetResponseStream()) )
{
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
}
catch (Exception e)
{
return "An error occured while generating your report.\n" +
e.Message;
}
return result;
}
anyone have any ideas/things I can try because I am at a loss. Thanks
in advance.I figured out my problem.
I was taking the stream reader and passing the results back to the
output stream and writing it out just using Response.Write. This
worked fine for Reporting Svcs RTM, but NOT for SP2.
After going through various postings, I gather a few ways that others
did similar web request/response calls and found that if I just passed
the raw response stream and wrote it out with
Response.outputstream.write that it worked for BOTH RTM and SP2..
System.IO.Stream rs =ReportBuilder.generateReportStream(ReportBuilder.ReportViewerFullPath);
Byte[] read = new Byte[1024];
int count = rs.Read(read, 0, read.Length);
while(count > 0)
{
Response.OutputStream.Write(read, 0, count);
count = rs.Read(read, 0, count);
}
Thursday, February 16, 2012
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment