Link to home
Start Free TrialLog in
Avatar of LuckyCold
LuckyCold

asked on

Retrieve reports from reporting server in Asp.Net (vs2005)

Dear experts,

I have created and uploaded a report (rdl) to our reporting server http://www.xxxx.com/Reports2005.

Now I want to retreive the report from the asp.net page. Can someone provide me the code on how to call it. I am very new to the SQLServer reporting  services.

Thanks for help.
Avatar of gigglick
gigglick

Include this namespace in you code behind:using System.Data.SqlClient;
Drop a ReportViewer control onto your asp page

Here is a snippit of code I use to refresh a report that has five parameters:
 ///refresh the report
            this.ReportViewer1.ServerReport.ReportServerUrl =
            new System.Uri("http://MyServer/reportserver");

            //while (this.ReportViewer1.ServerReport.IsDrillthroughReport)
            //{
            //    this.ReportViewer1.PerformBack();
            //}


                this.ReportViewer1.ServerReport.ReportPath = "/ReportFolder/ReportName";
           


            //this.ReportViewer1.ServerReport.ReportPath = strReport;

            Microsoft.Reporting.WebForms.ReportParameter[] RptParameters =
                new Microsoft.Reporting.WebForms.ReportParameter[5];

            //string strTime = System.DateTime.Now.ToShortTimeString();
            RptParameters[0] =
                new Microsoft.Reporting.WebForms.ReportParameter("account_ID", TheAccount.accountID.ToString());
            //RptParameters[1] =
            //   new Microsoft.Reporting.WebForms.ReportParameter("date", DropDownList2.Text.ToString());
            RptParameters[1] =
               new Microsoft.Reporting.WebForms.ReportParameter("statement_Date", DropDownList4.Text.ToString());
            RptParameters[2] =
                new Microsoft.Reporting.WebForms.ReportParameter("startdate", "6/30/2006".ToString());//this date doesn't matter its filler
            RptParameters[3] =
                new Microsoft.Reporting.WebForms.ReportParameter("enddate", DropDownList4.Text.ToString());
            RptParameters[4] =
                new Microsoft.Reporting.WebForms.ReportParameter("period", DropDownList2.Text.Substring(0, 1).ToString());

            this.ReportViewer1.ServerReport.SetParameters(RptParameters);

            this.ReportViewer1.ServerReport.Refresh();
            this.ReportViewer1.Visible = true;
Avatar of LuckyCold

ASKER

Hi Gigglick,
Thanks for the quick response.
I have implemented what you said and  I got the error message -  the attempt to connect to the report server failed. Check your connection information and that the report server is a compatible version.

The request failed with http status 404:not found.

Please advise.

Thanks a million,
Here is the code:


Imports System.Data.SqlClient


Partial Class _Default
    Inherits System.Web.UI.Page

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.ReportViewer1.ServerReport.ReportServerUrl = New System.Uri("http://myreportservername.com/reports2005")
        Me.ReportViewer1.ServerReport.ReportPath = "Reports/Report1"
        Me.ReportViewer1.ServerReport.Refresh()
        Me.ReportViewer1.Visible = True
    End Sub
End Class


Hi -

Sorry didn't realize you hadn't needed to connect to your server at all yet.   You'll need to set up a database connection: This shoudl come before the report server refresh code.

SqlConnection cn = new SqlConnection("Data Source=MyServer;Initial Catalog=MyDatabase;Integrated Security=True");
Hi Gigglick,
I am ready to go home and I'll try tonight.

Relmada, I already checked the site before I posted the questions. Thanks anyway.
Hi Gigglick,
Sorry for the late response. Howerver, I still got the same error "The request failed with HTTP status 404: Not Found. "  from the IE browser page.    On the ie browser address, it shows "http://localhost:1035/ReportingServices/Default.aspx", but my report is resided on the reporting server (myreportname)  not on my workstation.  Do you have any clues? Please help. Thanks a million.

 Here is the code on mydefault aspx page:


Imports Microsoft.VisualBasic
Imports System.Web.Configuration
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
    Inherits System.Web.UI.Page
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim connectionstring As String = "Data Source=MYDATASOURCE;Initial Catalog=TestDatabase;Integrated Security=True"
        Dim con As New SqlConnection(connectionstring)
        con.Open()
        Me.ReportViewer1.ServerReport.ReportServerUrl = New System.Uri("http://myreportname.com/reports2005")
        Me.ReportViewer1.ServerReport.ReportPath = "/Reports/Report1"
        Me.ReportViewer1.ServerReport.Refresh()
        Me.ReportViewer1.Visible = True
        con.Close()
    End Sub
End Class
First try taking the .com extension off your report server name in this line of code:

Me.ReportViewer1.ServerReport.ReportServerUrl = New System.Uri("http://myreportname.com/reports2005")

Hi Gigglick,
Yes, I tried it and still go the same error.
 

 
ASKER CERTIFIED SOLUTION
Avatar of gigglick
gigglick

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Gigglick,

It works now. I am going to close the solution

Thanks a lot for your help.
No probs. glad you got it working