Calling an SSRS report from .NET without using the SSRS Server

I know that I didn't phrase that title exactly correct, but here's the concept: This piece of code will allow you to create an .rdlc file (an SSRS report) in your Visual Studio project and then call that report from code; the SSRS report server will not be called. This is all Visual Studio and .NET, but produces a report.

This is a step by step guide to creating the report, it includes screen shots and code samples

 

In your .NET project (we've coded this example in Visual Studio 2010), add a new report to the project, be sure that it has the .rdlc extention.

 

 

The next several shots walk you through creating the data source. Everything that we do here is through a stored procedure, so we're going to hook up to a sproc. In the Report Data tab, click on New > Dataset

 

Go through the wizard as shown below

 

We're not showing the 'new connection' wizard, but that's what we did. Click on 'New Connection' and create a connection.

 

Here, we select the stored procedure.

 

Drop a few fields onto the report by clicking and dragging. We didn't waste a lot of time on formatting, this is just a 'proof of concept'

 

Add a form to your project called 'Report', add a ReportViewer control. Leave the name default to ReportViewer1.

Add this code to the form:

 

Imports Microsoft.VisualBasic
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports Microsoft.Dexterity.Bridge
Imports Microsoft.Dexterity.Applications
Imports Microsoft.Dexterity.Shell
 
Public Class Report
    Inherits DexUIForm
    Dim _DT As DataTable
    Dim _reportName As String
    Dim _dataSet As String
 
    Sub New(ByVal DT As DataTable, ByVal ReportName As String, ByVal DataSet As String)
 
        InitializeComponent()
 
        _DT = DT
        _reportName = ReportName
        _dataSet = DataSet
    End Sub
    Private Sub Report_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Print()
    End Sub
 
    Sub Print()
        Try
            ReportViewer1.Reset()
 
            ReportViewer1.LocalReport.DataSources.Clear()
            'this is the data set created when creating the report
            ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource(_dataSet, _DT))
 
            ReportViewer1.LocalReport.ReportEmbeddedResource = _reportName '"EWaddin.MarginReport.rdlc"
 
            Me.ReportViewer1.RefreshReport()
 
            'other options
            'ReportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout)
            'ReportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.PageWidth
 
        Catch ex As Exception
            FPCommon.ErrorHandler.globalErrorHandler(ex, True)
        End Try
    End Sub
End Class

 

Now we call the new report form like this:

 

Sub PrintReport()
    Dim oDT As DataTable = SPs.DD_CustomerSpeedEntry(Me.txtAccountNumber.Text).getTable
    Dim frm As New Report(oDT, "ValueAddin.CustomerSpeedEntry.rdlc", "DataSet1")
    frm.ShowDialog()
 
End Sub

 

Note that we're defining the dataset before going to the form, that makes the report form reusable for any report. We're passing in the name of the dataset and the name of the report also. In the example above, 'ValueAddin' is the name of the .NET project. Dunno why it's done like that... it just is.

 

Voila - an SSRS report that doesn't use the SSRS server. The report form does the work.

 

 

 

 

                       

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences