.NET Framework ADO.NET Using common interfaces to abstract away vendor specific classes

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!


var providerName = "System.Data.SqlClient";    //Oracle.ManagedDataAccess.Client, IBM.Data.DB2
var connectionString = "{your-connection-string}";
//you will probably get the above two values in the ConnectionStringSettings object from .config file

var factory = DbProviderFactories.GetFactory(providerName);
using(var connection = factory.CreateConnection()) {    //IDbConnection
    connection.ConnectionString = connectionString;
    using(var command = connection.CreateCommand()) {    //IDbCommand
        command.CommandText = "{query}";
        using(var reader = command.ExecuteReader()) {    //IDataReader
            while(reader.Read()) {

Got any .NET Framework Question?