An ADO.Net data provider connects to a data source such as SQL Server, MySQL, PostgreSQL but also ODBC and OLE DB data source, and provides a way to execute queries against that data source in a consistent manner that is independent of the data source and data source-specific functionality.
DubUrl doesn't remove the need to add a reference to the package containing the ADO.Net provider, neither the need to register the factory of the ADO.Net provider. Click here for more info
To embrace the world of DubUrl, you need to follow some conventions regarding the way you’re providing your connection URL. The table bellow is listing the different aliases than can be provided in the scheme but also the name of the ADO.Net data provider package and the name that you should use as the provider invariant name.
List of Native ADO.Net data providers
Additional packages
SQLite3 is expecting additional libraries (.dll) to work properly. If these libraries are missing, you ‘ll receive an exception You need to call SQLitePCL.raw.SetProvider()
. To avoid this exception, you must include the package SQLitePCLRaw_bundle_e_sqlite3
into your solution or copy the following dlls:
SQLitePCLRaw.batteries_v2.dll
SQLitePCLRaw.core.dll
SQLitePCLRaw.provider.e_sqlite3.dll
Example
Following example shows how to use DubUrl to connect to a PostgreSQL database.
Referencing the package of the ADO.Net data provider, using the package name described in the 3rd column of the table
dotnet add package Npgsql
Registering the factory of the ADO.Net data provider
DbProviderFactories.RegisterFactory("Npgsql", Npgsql.NpgsqlFactory.Instance);
Open a connection to the database named dbname and hosted on a server named serverName. Note that the scheme of the URL is set to pgsql to specify that the database is a PostgreSQL (other options than pgsql such as pg or postgres could have been used).
var conn = new ConnectionUrl("pgsql://{serverName}/{dbName}").Open();