Search code examples
c#databasesqliteoledb

Is there a database connection library out there that will handle multiple types of DB connections and operations (i.e. OleDb, SQLite, ADO, etc)?


What I have is an Access database that we are working on, but we need to convert it to SQLite and send it to another client while keeping the code working for the Access database as well for all others using our program.

Minimum of what I need is something that can handle connections and operations on Access and SQLite databases. Does something like this even exist. And I know the data and queries are different for these databases, I can handle that separately.

Are there any other suggestions for how to handle two separate database and this situation?

EDIT:

What I really need is something where I can do this:

public AnyDBConnection GetConnection(string connectionString)
{
    //I guess somehow this needs to know the DB type (OleDB, SQLite, etc.)
    return new AnyDBConnection(connectionString);
}

Solution

  • For a lower-level solution, all the ADO.NET classes have common base classes and interfaces, such as DbConnection, IDbConnection, etc. The interfaces are under the namespace System.Data while the abstract base classes are under System.Data.Common.

    Most 3rd-part ADO.NET libraries inherit/implement these so that all database-specific connections and commands and so on can be dealt with under these common interfaces. They should each also have a class deriving from DbProviderFactory for a centralized interface for creating the different concrete objects.

    You could have a CreateFactory method somewhere that looks up in configuration what database is being used and the connection string, then creates the appropriate factory object for you.