ADO.NET provider
LibRed.Ado is a complete ADO.NET provider: DbConnection, DbCommand, DbDataReader, DbParameter,
DbTransaction and DbProviderFactory. Use it on its own, with no EF Core involved, or under any library
built on ADO.NET’s base classes.
The types are in the LibRed.Data namespace.
using LibRed.Data;
using var connection = new LibRedConnection(@"Data Source=C:\Data\Northwind.accdb");connection.Open();
using var command = connection.CreateCommand();command.CommandText = "SELECT TOP 5 CustomerID, CompanyName FROM Customers WHERE Country = @country ORDER BY CompanyName";var country = command.CreateParameter();country.ParameterName = "@country";country.Value = "Germany";command.Parameters.Add(country);
using var reader = command.ExecuteReader();while (reader.Read()) Console.WriteLine($"{reader.GetString(0)} {reader.GetString(1)}");LibRed supports named parameters only: @name. A positional ? is refused.
Create a database
Section titled “Create a database”LibRedConnection.CreateDatabase(@"Data Source=C:\Data\New.accdb");CreateDatabase takes an optional collation and an optional format version. The default format is ACE 12
(Access 2007).
Provider factory
Section titled “Provider factory”DbProviderFactory factory = LibRedFactory.Instance;Connection strings
Section titled “Connection strings”| Key | Aliases | Meaning |
|---|---|---|
Data Source |
DataSource, DBQ |
The database file. Relative paths are expanded to a full path, and a name with no extension gets .accdb. |
Password |
Jet OLEDB:Database Password, PWD |
The database password, for an encrypted file. |
The aliases mean connection strings written for ACE’s OLE DB provider or ODBC driver work unchanged. A
connection string with no = in it is taken as the path itself.