We help IT Professionals succeed at work.

Calling SSRS from VS C# 2008

rwheeler23
rwheeler23 asked
on
This code always crashes on the line:

ReportViewer1.ServerReport.SetParameters(Parameters);    

Saying invalid path. I ahve trioed several variations with no luck. What am I missing?

public Form1()
        {
            InitializeComponent();

            ReportViewer ReportViewer1 = new ReportViewer();


            ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://datamining/reportserver");
            List<ReportParameter> Parameters = new List<ReportParameter>(); 
            string ParamValue = TextBox1.Text;  
            ///''This is just an example of getting the value of a textbox  
            Parameters.Add(new ReportParameter("BegDate", "01/01/2010"));
            Parameters.Add(new ReportParameter("EndDate", "12/31/2010"));
            ReportViewer1.ServerReport.ReportPath = "//datamining/Reports/Top20Vendors";  
            ReportViewer1.ServerReport.SetParameters(Parameters);  
            ReportViewer1.ProcessingMode = ProcessingMode.Remote;  
            ReportViewer1.ServerReport.Refresh(); 
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            this.reportViewer1.RefreshReport();
        }

Open in new window

Comment
Watch Question

try this,

ReportViewer1.ServerReport.ReportPath = "/datamining/Reports/Top20Vendors";  

or this,

ReportViewer1.ServerReport.ReportPath = "/Reports/Top20Vendors";  
By the way, the ReportPath path should be relative to the ReportServerUrl and therefore you should not be using // and should start with /.
rwheeler23President

Author

Commented:
When I run this report via SSRS this is the complete link.

http://datamining/Reports/Pages/Report.aspx?ItemPath=%2fTop20Vendors%2fTop+20+Vendors+by+Inventory+Transactions

Neither of the two options above work as I get the message "Report cannot be found".
rwheeler23President

Author

Commented:
In this case, SSRS is on one server and the reporting database is on another server. Should I be specifying the name of the server that contains the database and not just the SSRS engine?
Try doing this assuming Top20Vendors is your report definition file

ReportViewer1.ServerReport.ReportPath = "\\datamining\Reports\Top20Vendors";  

or

ReportViewer1.ServerReport.ReportPath = "\\Reports\Top20Vendors";  

or

ReportViewer1.ServerReport.ReportPath = "\Reports\Top20Vendors";

or

ReportViewer1.ServerReport.ReportPath = "\Top20Vendors";

or

ReportViewer1.ServerReport.ReportPath = Server.MapPath("Top20Vendors");  
 
 


rwheeler23President

Author

Commented:
None of the above work. For this line I get "Server does not exist in this context" Do I need to add a reference to this project?

ReportViewer1.ServerReport.ReportPath = Server.MapPath("Top20Vendors");  

I have also attached a screenshot of the properties of this report. I have check spelling and still do not understand why I keep getting report not found message.
Report-VS.jpg
OK.  Your Report Folder is Top20Vendors.  This is not the report definition file.  Are you sure you have your configuration right?  

In this case, try this,

ReportViewer1.ServerReport.ReportPath = "\\Top20Vendors\<Your report with no extensions (i.e. rdlc)>";

or

ReportViewer1.ServerReport.ReportPath = Server.MapPath("<Your report with no extensions>");
Also, I can see you have this "Top 20 Vendors by Inventory Transactions.rdl"  

if this is the report file then add this in the samples in my previous post.
By the way, try this as well just in case

ReportViewer1.ServerReport.ReportPath = "/Top20Vendors/<Your report with no extensions (i.e. rdlc)>";

Also,

based on my previous post, I don't know if this is it

ReportViewer1.ServerReport.ReportPath = "/Top20Vendors/Top 20 Vendors by Inventory Transaction";
Also, I am not sure if you have deployed your report to the report server already.

Check this link as well:

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Studio_.NET_2005/Q_23180356.html
rwheeler23President

Author

Commented:
OK, when I updated my code to read
ReportViewer1.ServerReport.ReportPath = "/Top20Vendors/Top 20 Vendors by Inventory Transactions";

I then get what you see in the attached screenshot. The program no longers crashes into Debug mode but the message is the same.
namespace TestReportViewer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            ReportViewer ReportViewer1 = new ReportViewer();


            ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://datamining/reportserver");
            List<ReportParameter> Parameters = new List<ReportParameter>(); 
            string ParamValue = TextBox1.Text;  
            ///''This is just an example of getting the value of a textbox  
            Parameters.Add(new ReportParameter("BegDate", "01/01/2010"));
            Parameters.Add(new ReportParameter("EndDate", "12/31/2010"));
            ReportViewer1.ServerReport.ReportPath = "/Top20Vendors/Top 20 Vendors by Inventory Transactions"; 
            /* ReportViewer1.ServerReport.ReportPath = Server.MapPath("Top20Vendors");  */

            ReportViewer1.ServerReport.SetParameters(Parameters);  
            ReportViewer1.ProcessingMode = ProcessingMode.Remote;  
            ReportViewer1.ServerReport.Refresh(); 
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            this.reportViewer1.RefreshReport();
            
        }
    }
}

Open in new window

TestReportViewer.bmp
Try renaming the report file to something shorter and if possible remove the spaces.

Something like

ReportViewer1.ServerReport.ReportPath = "/Top20Vendors/Top20Trans";

If you read the error message, there is a limit of 260 characters for the full path.
rwheeler23President

Author

Commented:
Here are the actual Build results coming out of BIDS. I have type the path in exactly as here and I keep getting the message about 260 characters. Could it be somehting about how SSRS is installed?
Build complete -- 0 errors, 0 warnings
------ Deploy started: Project: Top20Vendors, Configuration: Debug ------
Deploying to http://datamining/reportserver
Deploying data source '/Data Sources/POWMAT'.
Deploying report '/Top20Vendors/Top20Vendors'.
Deploy complete -- 0 errors, 0 warnings
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========
---->   Deploying report '/Top20Vendors/Top20Vendors'

It looks like you have two nested folders of the same name.

By the way, one test you can do is to try accessing the report through the Report Manager by accessing something like this,

http://datamining/reports/Pages/Folder.aspx

or

http://datamining/reportserver/Pages/Folder.aspx

Check the links below for reference:

http://msdn.microsoft.com/en-us/library/ms157145.aspx

http://odetocode.com/articles/215.aspx
rwheeler23President

Author

Commented:
The report runs just fine using Report Manager. I just do not understand why it keeps saying report not found when it is sitting right there. I even tried putting the code on the SSRS server and change the server name to localhost. I look at all the examples are they look just like mine. Is there any command I can issue to give me a listing of reports in thr SSRS database? If I could do that, perhaps I could see what it wants to use as a name.