Connecting to databases
Configure and register your provider
Add the package references and register the factories for the ADO.Net data providers
On this page
DubUrl parses database URLs and resolves providers. The ADO.NET provider package supplies the actual connection implementation; native drivers may be required separately.
Add a provider package
Choose the package listed for your database in Supported databases and aliases. For example:
dotnet add package Microsoft.Data.SqlClient
dotnet add package MySqlConnector
dotnet add package Npgsql
Install only the providers your application uses. For SQLite, the full Microsoft.Data.Sqlite package includes its default native SQLite bundle. Microsoft.Data.Sqlite.Core requires you to configure a compatible SQLitePCLRaw provider separately.
Register the provider factory
Register each selected factory at application startup, before resolving its connection URL:
using System.Data.Common;
DbProviderFactories.RegisterFactory("Microsoft.Data.SqlClient", Microsoft.Data.SqlClient.SqlClientFactory.Instance);
DbProviderFactories.RegisterFactory("MySqlConnector", MySqlConnector.MySqlConnectorFactory.Instance);
DbProviderFactories.RegisterFactory("Npgsql", Npgsql.NpgsqlFactory.Instance);
The invariant name is the provider identifier expected by DubUrl’s mapping. It is not universally the NuGet package name: some providers have different package and invariant names. The catalog lists the expected values.
Use explicit registration for predictable startup. DubUrl.Registering.ProviderFactoriesRegistrator is also available for assembly discovery, but it does not install missing packages or native drivers.
Continue
Open your first connection, or configure an ODBC driver or OLE DB provider when required.