Hello
We are trying to connect SSRS with an asp.net application.
But we get the following error: Cannot access a closed Stream.
We use the follow in code to access the report.
string strReportUser = @"user"; string strReportUserPW = "pwd"; string strReportUserDomain = ""; //Session["rp_DatePar"].ToString() DateTime DateNow = DateTime.ParseExact("15/05/2013", "dd/MM/yyyy", CultureInfo.InvariantCulture); string sTargetURL = "http://server/reportserver?%2f10139+-+Unibind+Scorecard&rs:Command=Render&rs:Format=PDF"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(sTargetURL); req.PreAuthenticate = true; //req.UseDefaultCredentials = true; req.Credentials = new System.Net.NetworkCredential( strReportUser, strReportUserPW, strReportUserDomain); HttpWebResponse HttpWResp = (HttpWebResponse)req.GetResponse(); Stream fStream = HttpWResp.GetResponseStream(); HttpWResp.Close(); //Now turn around and send this as the response.. byte[] fileBytes = ReadFully(fStream); // Could save to a database or file here as well. Response.Clear(); Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition","attachment; filename=\"ReportFor" +"test" + ".pdf\""); Response.BinaryWrite(fileBytes); Response.Flush(); Response.End(); } public static byte[] ReadFully(Stream input) { using (MemoryStream ms = new MemoryStream()) { input.CopyTo(ms); return ms.ToArray(); } }
Can somebody tell us what is going wrong?
First we also had had an authentication error 401 I don't know how we fixed it but we are not getting that error again.
Kind Regards
Matthias