[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1449
  • Last Modified:

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.
0
LuckyCold
Asked:
LuckyCold
  • 5
  • 5
1 Solution
 
gigglickCommented:
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;
0
 
LuckyColdAuthor Commented:
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


0
 
ralmadaCommented:
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
gigglickCommented:
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");
0
 
LuckyColdAuthor Commented:
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.
0
 
LuckyColdAuthor Commented:
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
0
 
gigglickCommented:
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")

0
 
LuckyColdAuthor Commented:
Hi Gigglick,
Yes, I tried it and still go the same error.
 

 
0
 
gigglickCommented:
http://localhost:1035/ReportingServices/Default.aspx"  I am assuming you are building the asp page on your local machine in visual studio which will open up on a local port which is the first part of that path.  The /ReportingServices/ should be the name of your project and Default.aspx is the default start up page.    If you are getting that error while you are trying to open the page this is likely an issue with your webconfig file.  You wont see the address for the report server appear in your address bar as all of that processing is being handled during the postback.   The code you have above should work so it sound like you've got other issues going on with your website.
0
 
LuckyColdAuthor Commented:
Hi Gigglick,

It works now. I am going to close the solution

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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now