DubUrl provides a standard, URL style mechanism for parsing database connection strings and opening DbConnections for .NET. With DubUrl, you can parse and open URLs for popular databases such as Microsoft SQL Server, PostgreSQL, MySQL, SQLite3, Oracle Database and most of the other SQL databases. This project is inspired from the package dburl available in the GoLang ecosystem and is trying to match the aliases for portocols.
About | Overview | Quickstart | Examples | Schemes | Installing | Using
Continuous integration builds:
Supported database connection URLs are of the form:
driver:alias://user:pass@host/dbname?opt1=a&opt2=b
Where:
Component | Description |
---|---|
alias | database type (see below) |
driver | driver/provider name (only for odbc/oleodbc) |
user | username |
pass | password |
host | host |
dbname* | database, instance, or service name/ID to connect to |
?opt1=... | additional database driver options (see respective SQL driver for available options) |
* for Microsoft SQL Server, /dbname
can be
/instance/dbname
, where /instance
is optional. For Oracle Database,
/dbname
is of the form /service/dbname
where /service
is the service name
or SID, and /dbname
is optional. Please see below for examples.
Database connection URLs in the above format can be parsed to a standard connection string with the [Parse
] as such:
string connectionUrl = "mssql://{server}/{database_name}";
string connectionString = new ConnectionUrl(connectionUrl).Parse();
Additionally, a simple helper, [Open
], is provided that will parse, open, and return a standard DbConnection
.
string connectionUrl = "mssql://{server}/{database_name}";
IDbConnection connection = new ConnectionUrl(connectionUrl).Open();
If you don't want to open the connection but only return it and manage its state by yourself, use the function [Connect
]
string connectionUrl = "mssql://{server}/{database_name}";
IDbConnection connection = new ConnectionUrl(connectionUrl).Connect();
The following are example database connection URLs that can be handled by
[Parse
], [Connect
] and [Open
]:
mssql://user:[email protected]/instance/dbname?keepAlive=10
oledb+mssql://user:pass@localhost/dbname
postgres://user:pass@localhost/dbname
odbc+postgres://user:pass@localhost:port/dbname?option1=
mysql://user:pass@localhost/dbname
oracle://user:[email protected]/sid
db2://user:pass@localhost/dbname
The following databases and their associated schemes are supported out of the box:
The following databases and their associated schemes are supported out of the box:
The following databases and their associated schemes are supported through the OLE DB data provider extension:
The following databases and their associated schemes are supported through the ADOMD.NET data provider extension:
Install in the usual .NET fashion:
Install-Package DubUrl
To install the extension for OLEDB provider locators
Install-Package DubUrl.OleDb
To install the extension for ADOMD.NET data provider
Install-Package DubUrl.Adomd
Check the first steps guide on the website.
Please note that DubUrl
does not install actual drivers, and only provides a standard way to [Parse
] respective database connection URLs then [Connect
] or [Open
] connections.