Avoid App.config file in project when using with SQLite/SubSonic (or any other database)

c#, configuration-files, database, sqlite, subsonic3

Solution

You can create a Provider manually by passing the connection string in:

var p = ProviderFactory.GetProvider("connectionstring", "System.Data.SqlClient");

Then you can use that Provider when you need to. This is ideal for IoC where you can setup a rule for SubSonic's IDataProvider:

ForRequestedType< IDataProvider >()
    .TheDefault.Is.ConstructedBy(x => 
        ProviderFactory.GetProvider("connectionstring", "System.Data.SqlClient"));

Gotta love IoC :)

Problem

I have a project which I am developing with SQLite and SubSonic 3. I want to know that how can I avoid the App.config file altogether. How do I tell my program to use SQLite Data provider. I mean, how can I tell it this: ``` <DbProviderFactories> <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite"> </DbProviderFactories> ``` also can I add a connection string by code: ``` <add name="xyz" connectionString="Data Source=xyz.db" providerName="System.Data.SQLite"/> ```

Original source