pass ssrs with report viewer

HI guys,

I'm trying to call SSRS (reporting server) through my ASP.NET mvc application.

This is the first time I'm doing it and I follow these steps:

First, I installed the ReportViewer.msi, then i got this file - ReportViewer.aspx in my solution.

Now I followed this article, but still get confuse and when I launch the application and go to the "ReportViewer.aspx" page, I'm getting error and can't see my report server.

Here is the error I'm getting.

report

Please, I need some good explanation and step by step as I'm very new to this process.


Thanks,
LVL 1
Moti Mashiah.NET DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

srikanthreddyn143Commented:
Did you give report server credentials in your code?
sammySeltzerCommented:
Hi Moti,

Here are the steps that I follow:

1, Right-click on your project and select Add New Item
    select either Report or Report Wizard. The difference is report wizard guides you through the process while
    selecting report is for the more experienced who know what they are doing.
    You will name it yourreport.rdlc
2, Next, again right-click on project and select Add New Item
    Select DataSet and name it whateveryouwant.xsd.
    This is where you write your sql statement or select a prepared statement like stored procedure and the    
    set your connection to your server and database.
3, Lastly, create the a .aspx file similar to the one you created already.
    Then drag yourreport.rdlc from Toolbox into the .aspx file. You will also be required to scriptManager into
    the .aspx.
Then follow the process to select the data set name you created and that's pretty much it.

There are some minor additional steps but you can figure those out.

At least for now, this will solve most of your issues.
Moti Mashiah.NET DeveloperAuthor Commented:
Hi guys,

Thanks for your answer, but I think I have some different situation here.

I have installed reporting viewer for mvc from Nuget packages. and I got package to work with.

Please, look at the two files code - that I got from this package.

view file:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReportViewer.aspx.cs" Inherits="ALThompsonCRM.ReportViewer" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <Scripts>
                <asp:ScriptReference Assembly="ReportViewerForMvc" Name="ReportViewerForMvc.Scripts.PostMessage.js" />
            </Scripts>
        </asp:ScriptManager> 
        <rsweb:ReportViewer ID="rptViewer"  runat="server">
            <ServerReport ReportPath="http://srv-db-01:8081/Reports/Pages/Report.aspx"/>
        </rsweb:ReportViewer>
    </form>
</body>
</html>

Open in new window


Server C# code:
public partial class ReportViewer : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            ShowReport("rptViewer");
        }

        private void ShowReport(string url)
        {
            try
            {
                
                //report url  
                string urlReportServer = url;

                // ProcessingMode will be Either Remote or Local  
                rptViewer.ProcessingMode = ProcessingMode.Remote;

                //Set the ReportServer Url  
                rptViewer.ServerReport.ReportServerUrl = new Uri(urlReportServer);

                // setting report path  
                //Passing the Report Path with report name no need to add report extension   
                rptViewer.ServerReport.ReportPath = "/Home/IT Department";

                //Set report Parameter  
                //Creating an ArrayList for combine the Parameters which will be passed into SSRS Report  
                //ArrayList reportParam = new ArrayList();  
                //reportParam = ReportDefaultPatam();  

                //ReportParameter[] param = new ReportParameter[reportParam.Count];  
                //for (int k = 0; k < reportParam.Count; k++)  
                //{  
                //    param[k] = (ReportParameter)reportParam[k];  
                //}  

                // pass credential as if any... no need to pass anything if we use windows authentication  
                IReportServerCredentials irc = new CustomReportCredentials("amol", "masterB4", "172.16.1.4");
                rptViewer.ServerReport.ReportServerCredentials =irc;
                

                //pass parameters to report  
                //rptViewer.ServerReport.SetParameters(param);   
                rptViewer.ServerReport.Refresh();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public class CustomReportCredentials : IReportServerCredentials
        {
            private string _UserName;
            private string _PassWord;
            private string _DomainName;

            public CustomReportCredentials(string UserName, string PassWord, string DomainName)
            {
                _UserName = UserName;
                _PassWord = PassWord;
                _DomainName = DomainName;
            }

            public System.Security.Principal.WindowsIdentity ImpersonationUser
            {
                get { return null; }
            }

            public ICredentials NetworkCredentials
            {
                get { return new NetworkCredential(_UserName, _PassWord, _DomainName); }
            }

            public bool GetFormsCredentials(out Cookie authCookie, out string user,
             out string password, out string authority)
            {
                authCookie = null;
                user = password = authority = null;
                return false;
            }
        }
    }

Open in new window

OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Moti Mashiah.NET DeveloperAuthor Commented:
Guys,

I would like to mention that I don't need credential as my users depend on Active directory and got access to reporting server automatically.
srikanthreddyn143Commented:
IReportServerCredentials irc = new CustomReportCredentials("amol", "masterB4", "172.16.1.4");
                rptViewer.ServerReport.ReportServerCredentials =irc;

Does this username has access?
Moti Mashiah.NET DeveloperAuthor Commented:
Yes
srikanthreddyn143Commented:
rptViewer.ServerReport.ReportServerUrl = new Uri(urlReportServer);

isn't it urlReportServer is a full path like http:\\XXXXXX

it should be the path where your reports are hosted.
Moti Mashiah.NET DeveloperAuthor Commented:
This is the variable for urlReportServer:  "string urlReportServer = "http://srv-db-01:8081/ReportServer/";"

this is the full path for the reporting server.

Anyways now I'm getting something in the page but can't see the report:
Here is the path for the report:
rptViewer.ServerReport.ReportPath = "/IT_Department/Gift_cards/check_if_gift_cards_are_out_of_balance";
Moti Mashiah.NET DeveloperAuthor Commented:
I would like to show you what I'm getting now.

Please, see attachment:
Capture.PNG
Moti Mashiah.NET DeveloperAuthor Commented:
I added the server path to the view =  <ServerReport ReportServerUrl="http://srv-db-01:8081/reportserver" />

still same things show me just the bar.
srikanthreddyn143Commented:
Looks like you are not passing any parameter. Can you refresh the report and see if it is trying to do anything? Also, can you try running the report on report server with parameters you are passing if I misstated about your parameters?
Moti Mashiah.NET DeveloperAuthor Commented:
I not passing any parameters. I thought that it is not require to pass parameters in case you don't need or should you pass parameters anyways in any cases?.

I also didn't assign credential as my login user has full permission to the SSRS server.

Please, let me know.

Here is my code(pay attention for the comment out code.

 try
            {


                //report url  
                string urlReportServer = "http://srv-db-01:8081/ReportServer/";

                // ProcessingMode will be Either Remote or Local  
                rptViewer.ProcessingMode = ProcessingMode.Remote;

                //Set the ReportServer Url  
                rptViewer.ServerReport.ReportServerUrl = new Uri(urlReportServer);

                // setting report path  
                //Passing the Report Path with report name no need to add report extension   
                rptViewer.ServerReport.ReportPath = "/IT_Department/Gift_cards/check_if_gift_cards_are_out_of_balance";

                //Set report Parameter  
                //Creating an ArrayList for combine the Parameters which will be passed into SSRS Report  
                //ArrayList reportParam = new ArrayList();  
                //reportParam = ReportDefaultPatam();  

                //ReportParameter[] param = new ReportParameter[reportParam.Count];  
                //for (int k = 0; k < reportParam.Count; k++)  
                //{  
                //    param[k] = (ReportParameter)reportParam[k];  
                //}  

                //pass credential as if any... no need to pass anything if we use windows authentication  
                //IReportServerCredentials irc = new CustomReportCredentials("adm-mmashiah", "masterB4", "alt.local");
                //rptViewer.ServerReport.ReportServerCredentials = irc;


                //pass parameters to report  
                //rptViewer.ServerReport.SetParameters(param);   
                //rptViewer.ServerReport.Refresh();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

Open in new window

srikanthreddyn143Commented:
//rptViewer.ServerReport.Refresh();

Why was this line commented?

And also you dont need slash at the end of url
http://srv-db-01:8081/ReportServer/
Moti Mashiah.NET DeveloperAuthor Commented:
K, I uncomment the rptviewr.serverreport.refresh(); and I took the / from the end of reportserver.

I'm still getting the same issue:

here is my code after the changes you suggested:

 private void ShowReport()
        {
            try
            {


                //report url  
                string urlReportServer = "http://srv-db-01:8081/ReportServer";

                // ProcessingMode will be Either Remote or Local  
                rptViewer.ProcessingMode = ProcessingMode.Remote;

                //Set the ReportServer Url  
                rptViewer.ServerReport.ReportServerUrl = new Uri(urlReportServer);

                // setting report path  
                //Passing the Report Path with report name no need to add report extension   
                rptViewer.ServerReport.ReportPath = "/IT_Department/Gift_cards/check_if_gift_cards_are_out_of_balance";

                //Set report Parameter  
                //Creating an ArrayList for combine the Parameters which will be passed into SSRS Report  
                //ArrayList reportParam = new ArrayList();  
                //reportParam = ReportDefaultPatam();  

                //ReportParameter[] param = new ReportParameter[reportParam.Count];  
                //for (int k = 0; k < reportParam.Count; k++)  
                //{  
                //    param[k] = (ReportParameter)reportParam[k];  
                //}  

                //pass credential as if any... no need to pass anything if we use windows authentication  
                //IReportServerCredentials irc = new CustomReportCredentials("adm-mmashiah", "masterB4", "alt.local");
                //rptViewer.ServerReport.ReportServerCredentials = irc;


                //pass parameters to report  
                //rptViewer.ServerReport.SetParameters(param);   
                rptViewer.ServerReport.Refresh();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

Open in new window

Moti Mashiah.NET DeveloperAuthor Commented:
Guys, now I'm getting to pass the parameters and all working fine just the report is not rendering.

Please, see attachment of one of my report which doesn't need parameter.

Capture.PNG

PLEASE,HELP.
Moti Mashiah.NET DeveloperAuthor Commented:
Solved the issue:

the viewer ID was written as report so I changed it to reportviwer1.

:)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Moti Mashiah.NET DeveloperAuthor Commented:
As usual i find the solution by myself.:)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.