Link to home
Start Free TrialLog in
Avatar of rwheeler23
rwheeler23Flag for United States of America

asked on

Calling SSRS from VS C# 2008

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

Avatar of Alfred A.
Alfred A.
Flag of Australia image

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 /.
Avatar of rwheeler23

ASKER

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".
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");  
 
 


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
ASKER CERTIFIED SOLUTION
Avatar of Alfred A.
Alfred A.
Flag of Australia image

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
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:

https://www.experts-exchange.com/questions/23180356/How-To-Access-The-Reports-From-Reports-Project-ReportServer-via-ReportViewer-Control.html
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.
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
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.