Firstly, please make sure you published the reports to our reporting server, you can read following article to publish your reports. Click Here to publish your reports via visual studio.
There is a sample code to connect your reports via asp.net application.
C#:
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ 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">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<rsweb:ReportViewer ID="ReportViewer1" runat="server">
</rsweb:ReportViewer>
</form>
</body>
</html>
Default.aspx.cs
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)
{
if (!this.IsPostBack)
{
ReportViewer1.Width = 800;
ReportViewer1.Height = 600;
ReportViewer1.ProcessingMode = ProcessingMode.Remote;
IReportServerCredentials irsc = new CustomReportCredentials("reportingUser", "YourPassword", "SSRS Server"); // e.g.: ("demo-001", "123456789", "sql5090")
ReportViewer1.ServerReport.ReportServerCredentials = irsc;
ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://sql5090.site4now.net/ReportServer");
ReportViewer1.ServerReport.ReportPath = "/ReportingRootFolder/ReportingFile"; //e.g.: /demo-001/test
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;
}
}
VB.NET:
Default.aspx
<%@ Page Language="vb" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 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">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<rsweb:ReportViewer ID="MyReportViewer" runat="server" SizeToReportContent="True" Height="100%">
</rsweb:ReportViewer>
</form>
</body>
</html>
Default.aspx.vb
Imports Microsoft.VisualBasic
Imports Microsoft.Reporting.WebForms
Imports System.Net
Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Try
MyReportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
Dim cred As New ReportServerCredentials("test-001", "pwd", "sql5090")
MyReportViewer.ServerReport.ReportServerCredentials = cred
MyReportViewer.ServerReport.ReportServerUrl = New Uri("http://sql5090.site4now.net/ReportServer")
MyReportViewer.ServerReport.ReportPath = "/test-001/test"
MyReportViewer.ShowPrintButton = True
'add parameters to report
If 1 = 1 Then
'new add report Parameters
Dim reportParameterCollection As Microsoft.Reporting.WebForms.ReportParameter() = New Microsoft.Reporting.WebForms.ReportParameter(0) {}
reportParameterCollection(0) = New Microsoft.Reporting.WebForms.ReportParameter()
'Parameter Name
reportParameterCollection(0).Name = "ID"
'Parameter Value
reportParameterCollection(0).Values.Add("119644")
MyReportViewer.ServerReport.SetParameters(reportParameterCollection)
End If
Catch
End Try
End If
End Sub
End Class
Public Class ReportServerCredentials
Implements IReportServerCredentials
Private _userName As String
Private _password As String
Private _domain As String
Public Sub New(ByVal userName As String, ByVal password As String, ByVal domain As String)
_userName = userName
_password = password
_domain = domain
End Sub
Public ReadOnly Property ImpersonationUser() As System.Security.Principal.WindowsIdentity Implements Microsoft.Reporting.WebForms.IReportServerCredentials.ImpersonationUser
Get
Return Nothing
End Get
End Property
Public ReadOnly Property NetworkCredentials() As ICredentials Implements Microsoft.Reporting.WebForms.IReportServerCredentials.NetworkCredentials
Get
Return New NetworkCredential(_userName, _password, _domain)
End Get
End Property
Public Function GetFormsCredentials(ByRef authCookie As System.Net.Cookie, ByRef userName As String, ByRef password As String, ByRef authority As String) As Boolean Implements Microsoft.Reporting.WebForms.IReportServerCredentials.GetFormsCredentials
userName = _userName
password = _password
authority = _domain
Return Nothing
End Function
End Class
Note: Please do not forgot to replace parameters in source file.
You can download the template directly
here
Article ID: 1705, Created: May 7, 2015 at 1:16 AM, Modified: October 26, 2022 at 8:17 AM