webform visual tutorial studio ssrs services instalar ejemplo c# asp.net reporting-services ssrs-2008

visual - reportviewer c# windows forms



Pasando Credenciales a Sql Report Server 2008 (4)

He encontrado la solución para esto. primero debe establecer las credenciales y luego debe establecer el parámetro para el visor de informes.

rvCommon.ProcessingMode = ProcessingMode.Remote; rvCommon.ServerReport.ReportServerUrl = new System.Uri("SSRSReportServerURL"); rvCommon.ServerReport.ReportPath = "/Report Parts/CustomerMainReport2" ; Microsoft.Reporting.WebForms.ReportParameter[] RptParameters = new Microsoft.Reporting.WebForms.ReportParameter[1]; rvCommon.ServerReport.ReportServerCredentials = new ReportCredentials("username", "password", ""); RptParameters[0] = new Microsoft.Reporting.WebForms.ReportParameter("CustomerId", "1"); rvCommon.ServerReport.SetParameters(RptParameters); rvCommon.ServerReport.Refresh();

Soy bastante nuevo en C # y mi inglés no es tan bueno. Lo siento por adelantado si me olvido de un punto.

Intenté crear un sitio web ASP.NET con un control ReportService . Como ya sabrá, SSRS 2008 no permite el inicio de sesión anónimo. Entonces, intenté pasar las Credenciales a SSRS que se almacenarán dentro de mi página web para que los usuarios puedan ver el informe sin iniciar sesión.

Encontré el código a continuación y lo puse en mi WebForm , pero tengo un problema con los parámetros del informe.

  • Si hay valores predeterminados para los parámetros del informe, el código siguiente funciona bien.

  • Pero, si intento cambiar el valor de un parámetro, toda la página es
    actualizado y antes de hacer clic en el botón "Ver informe", todos
    los parámetros se restablecen a los valores predeterminados o nulos.

¿Alguna sugerencia sobre cómo evitar la actualización de toda la página u otra forma de pasar la información de inicio de sesión a SSRS? Muchas gracias por adelantado.

using System; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Net; using Microsoft.Reporting.WebForms; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { ReportViewer1.Width = 800; ReportViewer1.Height = 600; ReportViewer1.ProcessingMode = ProcessingMode.Remote; IReportServerCredentials irsc =new CustomReportCredentials("administrator", "MYpassworw", "domena"); ReportViewer1.ServerReport.ReportServerCredentials = irsc; ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://192.168.0.1/ReportServer/"); ReportViewer1.ServerReport.ReportPath = "/autonarudzba/listanarudzbi"; ReportViewer1.ServerReport.Refresh(); } } 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; } }


Hice una nueva función y la seleccioné en la vista de diseño de propiedades, eventos, reportViewer. (En la selección INIT i)

Después de eso, la página funciona normalmente y puedo cambiar los valores de los parámetros.

Default.aspx ahora se ve como:

</head> <body> <form id="form1" runat="server"> <div> <rsweb:ReportViewer ID="ReportViewer1" runat="server" onload="Admir"> </rsweb:ReportViewer> </div> </form> </body>

Y Default.aspx.cs se ve así

public void Admir(object sender, EventArgs e) { ReportViewer1.Width = 800; ReportViewer1.Height = 600; ReportViewer1.ProcessingMode = ProcessingMode.Remote; IReportServerCredentials irsc = new CustomReportCredentials("administrator", "mypass", "domena"); ReportViewer1.ServerReport.ReportServerCredentials = irsc; ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://192.168.0.1/ReportServer/"); ReportViewer1.ServerReport.ReportPath = "/autonarudzba/listanarudzbi"; ReportViewer1.ServerReport.Refresh(); } protected void Page_Load(object sender, EventArgs e) { }


Puedes usar el siguiente código en el evento de carga de página para dar parámetros.

ReportParameter[] reportParameterCollection = new ReportParameter[1]; //Array size describes the number of paramaters. reportParameterCollection[0] = new ReportParameter(); reportParameterCollection[0].Name = "ACCMGR"; //Give Your Parameter Name reportParameterCollection[0].Values.Add("12"); //Pass Parametrs''s value here. ReportViewer1.ServerReport.SetParameters(reportParameterCollection); ReportViewer1.ServerReport.Refresh();

Espero que esto te funcione.


Realmente no me he metido con SSRS, pero mi sombrero de ASP.NET me dice que es posible que desee envolver esas cosas en un bloque if (!IsPostBack) para evitar que se ejecute en la actualización de la página. Mi conjetura es que ReportViewer1.ServerReport.Refresh() extrae los valores predeterminados nuevamente.

protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { ReportViewer1.Width = 800; ReportViewer1.Height = 600; ReportViewer1.ProcessingMode = ProcessingMode.Remote; IReportServerCredentials irsc =new CustomReportCredentials("administrator", "MYpassworw", "domena"); ReportViewer1.ServerReport.ReportServerCredentials = irsc; ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://192.168.0.1/ReportServer/"); ReportViewer1.ServerReport.ReportPath = "/autonarudzba/listanarudzbi"; ReportViewer1.ServerReport.Refresh(); } }