Skip to content

MySQL Connection

Peter Gill edited this page Jun 8, 2026 · 1 revision

MySQL Connection

Majorsilence Reporting includes built-in support for MySQL via the MySQL.NET data provider, which uses the MySql.Data connector.

NuGet package

The MySQL connector is included as a dependency of the engine packages — no additional NuGet package is required in your application project. The provider is registered automatically when RdlEngineConfigInit() is called.

dotnet add package Majorsilence.Reporting.RdlEngine
# or for Linux/macOS
dotnet add package Majorsilence.Reporting.RdlEngine.SkiaSharp

Connection string format

Server=localhost;Port=3306;Database=mydb;Uid=myuser;Pwd=mypassword;

Common options:

Option Example Notes
Server localhost or 192.168.1.10 Hostname or IP
Port 3306 Default MySQL port
Database mydb Schema/database name
Uid myuser Username
Pwd mypassword Password
SslMode Required None, Preferred, Required
CharSet utf8mb4 Recommended for Unicode support
ConnectionTimeout 30 Seconds

Full reference: MySql.Data connection string options

New Report wizard

  1. Open the designer and click New Report (or File → New Report).
  2. On the Connection tab, select MySQL.NET from the provider drop-down.
  3. Enter the connection string and click Test Connection.
  4. Continue through the wizard to select tables and build the report.

Setting the connection string from code

Use OverwriteConnectionString on RDLParser to inject a runtime connection string:

using Majorsilence.Reporting.Rdl;

RdlEngineConfig.RdlEngineConfigInit();

var rdlp = new RDLParser(await File.ReadAllTextAsync("report.rdl"))
{
    Folder = @"C:\reports",
    OverwriteConnectionString = "Server=prod-db;Database=sales;Uid=app;Pwd=secret;"
};
using var report = await rdlp.Parse();
await report.RunGetData(null);

See Set Connection String — Runtime for the full runtime override pattern.

Using an existing connection

To reuse an open MySqlConnection (for transaction support or connection pooling), assign it directly to the report's DataSource:

using MySql.Data.MySqlClient;
using Majorsilence.Reporting.Rdl;

RdlEngineConfig.RdlEngineConfigInit();

var rdlp = new RDLParser(await File.ReadAllTextAsync("report.rdl"));
using var report = await rdlp.Parse();

using var conn = new MySqlConnection("Server=localhost;Database=mydb;Uid=app;Pwd=secret;");
await conn.OpenAsync();

// Assign the live connection to the report's data source
report.DataSources["DataSourceName"].UserConnection = conn;

await report.RunGetData(null);

The DataSource name must match the one defined in the report's dataset properties.

Troubleshooting

"Data provider not found" or empty results

  • Confirm RdlEngineConfig.RdlEngineConfigInit() was called before parsing.
  • Verify MySql.Data.dll is present in the output directory. If using a trimmed publish, ensure the assembly is not trimmed away.

Authentication errors

  • MySQL 8.0+ defaults to caching_sha2_password authentication. If MySql.Data version is old, it may not support this. Add AllowPublicKeyRetrieval=True to the connection string, or upgrade to a newer MySql.Data package.

SSL errors

  • Add SslMode=None to the connection string for local development, or configure a proper SSL certificate for production.

Clone this wiki locally