Create barcodes in a Reporting Services Report with SQL Server Data Tools
SQL Server Data Tools (SSDT) is a modern development tool for building SQL Server relational databases, Azure SQL databases, Analysis Services data models, Integration Services packages, and Reporting Services reports. This tutorial illustrates how to create industrial quality barcodes in a Reporting Services Report with SSDT using Visual Studio.
- Visual Studio 2017 or 2019 with Microsoft Reporting Services Projects templates installed
- SQL Server Data Tools (SSDT) for Visual Studio or Standalone installed. The SSDT component can be found in Visual Studio installer -> Workloads -> Data storage and processing.
- SQL Server 2017 or 2019 installed
- AdventureWorks database (or other database) installed
- Microsoft Reporting Services installed
- ConnectCode Barcode Software and Fonts installed
Configuring Visual Studio
You need to copy "ConnectCodeBarcodeFontsLibrary.dll" (Resource\Net DLL Integration Samples\DLL\.Net4.0 subdirectory) to the "SSRS" directory of Visual Studio. The default location of this directory is at
You will also need to copy "ConnectCodeBarcodeFontsLibrary.dll" to the "PrivateAssemblies" directory of Visual Studio.
Editing "RSPreviewPolicy.config" to grant FullTrust permission
The "RSPreviewPolicy.config" is the preview policy file of Report Designer.
The following tag needs to be added to the "RSPreviewPolicy.config" file to grant FullTrust permission to the "ConnectCodeBarcodeFontsLibrary.dll". This is required for previewing a Report that uses a DLL in the Report Designer.
Configuring Reporting Services
At a file level SQL Server Reporting Services is now completely separated from SQL Server file structure. This different from previous versions of Reporting Services and SQL Server.
You need to copy "ConnectCodeBarcodeFontsLibrary.dll" (Resource\Net DLL Integration Samples\DLL\.Net4.0 subdirectory) to the "ReportServer\bin" directory of SQL Server Reporting Services. The default location of this directory is at
Editing "rssrvpolicy.config" to grant FullTrust permission
The "rssrvpolicy.config" is the Report Server policy configuration file. The default path for this file is shown below:
The following tag needs to be added to the "rssrvpolicy.config" file. It grants FullTrust permission to ConnectCodeBarcodeFontsLibrary.dll in the Report Server.
Create barcodes in a Report Server project (SSDT Reporting Services)
1. Launch Visual Studio and create a new Project. Select "Report Server Project Wizard". Enter a name for your project and click on the "OK" button. If you did not see the "Report Server Project Wizard" item in your project type, make sure you have installed SSDT successfully.
2. A "Welcome to the Report Wizard" will be launched to provide you with an overview of the steps required to create a report. Click on the "Next" button. You should see the "Select the Data Source" dialog as shown below:
3. Click on the "Edit" button to setup the Data source. In the screenshot below our "AdventureWorks" database is stored in the "DESKTOP-UNTIFK9" Server with Windows Authentication. You can choose to setup the connection to your own database. After setting up the properties, you can click on the "Test Connection" button to ensure a successful connection before proceeding. Click on the "OK" button when you are ready.
4. In the "Select the Data Source" dialog, click on the "Next" button. In the "Design the Query" dialog, click on the "Query Builder" button. You should see the following dialog as shown in the screenshot below:
5. We are going to select 3 fields (columns) from the "Production" table. Enter the following query and click on the "OK" button:
6. In the "Select the Report Type" dialog, select a "Tabular" report and click on the "Next" button. In the "Design the Table" dialog, select all the available fields and add them to the "Details" section as shown below:
7. Click on the "Next" button followed by the "Finish" button.
8. We have now successfully created Reporting Services (.rdl) report in Visual Studio. If you are using Visual Studio 2019, click on "Report1.rdl" in "Solutions Explorer", and then the "..." button in "Properties -> Assemblies". If you are using Visual Studio 2017, you can click on the "Report -> Report Properties" menu item. This will launch the Report Properties dialog. We are going to add a reference to our "ConnectCodeBarcodeFontsLibrary.dll". This DLL (Dynamic Link Library) will be used to generate a barcode in the report.
Click on the "References" tab and click on the "Add" button followed by the "..." button to add an assembly. In the "Add Reference" dialog, click on the "Browse" tab and navigate to the "C:\Program Files (x86)\ConnectCode\Resource\Net DLL Integration Samples\.Net4.0" folder. Select the "ConnectCodeBarcodeFontsLibrary.dll" and click on the "OK" button.
Click on the "Add" button in "Add or remove classes". Enter "Net.ConnectCode.Barcode.BarcodeFonts" as the class name and "barcode" as the instance name and click on the "OK" button. We have successfully added a reference to the DLL and created an instance object for generating barcodes.
9. Click on the Code tab and enter the following:
The programming codes above uses the barcode instance object to generate a Code 128 (Auto Subset) barcode. In a Code 128 barcode, the check digit is mandatory. For some barcodes such as Code 39, the check digit is optional. You can use the following line to turn the check digit on or off.
Next, click on the "OK" button to exit from the "Report Properties" dialog.
10. In the "Design" tab of "Report1.rdl", right click on the last column of the table and select "Insert Column->Right". We are going to add a column for our barcodes.
11. In the Toolbox, select a "Text box"object and add it into the column from the previous step. The output characters generated by the DLL will be placed in the "Text box".
12. Right click on the "Text Box" object and select "Expression". Enter the following expression:
If you recall, "MakeBarcode" is a function we have defined in "Report Properties". And, in the above, we apply the function on the "ProductNumber" field. The result will be placed in the "Text box" field.
13. In the previous steps, we have defined a "MakeBarcode" function that uses the "ConnectCodeBarcodeFontsLibrary.dll" to generate a barcode. To be more exact, the "MakeBarcode" function returns a stream of output characters. These output characters when applied with a barcode font gives you an industrial quality barcode.
Next, we are going to apply a barcode font to the "Text box" that contains our output characters. Click on the "Text box" object and expand the "Font" properties as shown below. Set the "Font" to "CCode128_S3" (or "CCode128_S3_Trial") and "FontSize" to "24". You can reduce or increase the "FontSize" later to meet the size requirements of your barcode. The registered package of ConnectCode Barcode Software and Fonts also comes with a complete set of fonts with different heights to satisfy all requirements required by the auto-id industry.
14. Save all the files and click on the "Preview" tab. You should see the following report with Code 128 barcodes generated using the "ProductNumber" field.
The complete list of barcode API functions and fonts available are described at the following: