Moti Mashiah
asked on
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.
Please, I need some good explanation and step by step as I'm very new to this process.
Thanks,
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.
Please, I need some good explanation and step by step as I'm very new to this process.
Thanks,
Did you give report server credentials in your code?
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.
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.
ASKER
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:
Server C# code:
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>
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;
}
}
}
ASKER
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.
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.
IReportServerCredentials irc = new CustomReportCredentials("a mol", "masterB4", "172.16.1.4");
rptViewer.ServerReport.Rep ortServerC redentials =irc;
Does this username has access?
rptViewer.ServerReport.Rep
Does this username has access?
ASKER
Yes
rptViewer.ServerReport.Rep ortServerU rl = new Uri(urlReportServer);
isn't it urlReportServer is a full path like http:\\XXXXXX
it should be the path where your reports are hosted.
isn't it urlReportServer is a full path like http:\\XXXXXX
it should be the path where your reports are hosted.
ASKER
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.Rep ortPath = "/IT_Department/Gift_cards /check_if_ gift_cards _are_out_o f_balance" ;
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.Rep
ASKER
ASKER
I added the server path to the view = <ServerReport ReportServerUrl="http://srv-db-01:8081/reportserver" />
still same things show me just the bar.
still same things show me just the bar.
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?
ASKER
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.
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;
}
}
//rptViewer.ServerReport.R efresh();
Why was this line commented?
And also you dont need slash at the end of url
http://srv-db-01:8081/ReportServer/
Why was this line commented?
And also you dont need slash at the end of url
http://srv-db-01:8081/ReportServer/
ASKER
K, I uncomment the rptviewr.serverreport.refr esh(); 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:
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;
}
}
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
As usual i find the solution by myself.:)