views:

408

answers:

1

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"/>
+2  A: 

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 :)

Rob Conery
Wow Rob. It works flawlessly. Thanks. :)
Yogesh
is it possible to do similarly in SubSonic 2?
Rory