Skip to main content

Run a Report with SQL Data in the .NET Embedded Engine

This tutorial will guide you through running a document with SQL data in the .NET Embedded Engine with C#. It will go over installing the .NET Embedded Engine, and setting up the code to run a report with SQL data.

tip

Before installation of the .NET Embedded Engine, make sure you meet the requirements and have the necessary pre-requisites installed. Those can be found here.

Install the .NET Embedded Engine

There are two ways to install the .NET Embedded Engine.

  1. NuGet Package Manager
  2. Manual Installation with zip file

NuGet Package Manager

The first approach is to use NuGet Package Manager via Visual Studio to install the .NET Embedded Engine into your application. This approach is simple as you only need to reference the NuGet package to get started. Those steps can be found here.

Manual Installation with zip file

The other approach is referencing the .NET Embedded Engine by downloading the zip file which contains the necessary DLLs. These can be found on our downloads page here.

Once you have downloaded the zip file, extract the contents and reference the DLLs in your project. The steps to do this can be found here.

Setup the Properties

Once you have installed the .NET Embedded Engine, you will need to set up the necessary properties in the properties file so you can generate documents. In your project's config file you will need to add the WindwardReports section. This section will contain the properties related to document generation. The only property that is required to get started is the license. If this is empty you can still generate output, however it will contain a watermark.

To add your license key or any report properties, you need to add a WindwardReports section to your projects .config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
.
.
<WindwardReports>
<add key="license" value="[[LICENSE]]"/>
</WindwardReports>
.
.
</configuration>
tip

To learn more about the different properties we provide for report generation, check out this article.

Generating a Document

Now that you have the .NET Embedded Engine installed and the properties set up, you can start generating documents. Below is an example of how to generate a document with SQL data.

using System.IO;
using net.windward.api.csharp;
using WindwardInterfaces.net.windward.api.csharp;

namespace RunReportSql
{
class RunReportSql
{
static void Main(string[] args)
{
// Initialize the engine
Report.Init();

// Open template file and create output file
FileStream template = File.OpenRead("SQL Server - Template.docx");
FileStream output = File.Create("Report.pdf");

// Create report process
Report myReport = new ReportPdf(template, output);

string strConn = "Data Source=mssql.windward.net;Initial Catalog=Northwind;User ID=demo;Password=demo";

// SQL data source
using (AdoDataSourceImpl adoDatasource = new AdoDataSourceImpl("System.Data.SqlClient", strConn)) {
//run the report process
myReport.ProcessSetup();
// The second parameter is the user given name of the data source in the template
myReport.ProcessData(adoDatasource, "MSSQL");
myReport.ProcessComplete();
}

//close out of our template file and output
output.Close();
template.Close();

// Open the finished report
string fullPath = Path.GetFullPath("Report.pdf");
System.Diagnostics.Process.Start(fullPath);
}
}
}