I’m building an app around the servicestack framework and need to be able to access data in both Oracle and MS Sql Server. Is this possible using ORMLite, it seems that I can only set a single dialect for the App or have I missed something?
Share
Yes it is possible and support for this is already built into the
OrmLiteConnectionFactory, see the Master SQLServer + Sqlite shard example on OrmLite’s project home page.Basically you would register your default (or master) connection first with:
Then you would register a named connection for every other connection you wish to support, e.g:
Once that’s configured, opening a connection without specifying a name will open a connection to the default database, e.g:
Whilst you can specify a name to open up a named connection to a db with a different provider, e.g:
Manually use different Dialect Providers
The differences between the SQL Provider implementations between different RDBMS’s are contained within each dialect provider. So if you want to use OrmLite’s convenience extension methods against an specific ADO.NET provider implementation you just need to assign the ThreadStatic DialectProvider you wish to use, e.g:
This is essentially all what
RegisterConnectionin OrmLiteConnectionFactory automatically does behind the scenes for you.For reference here are all the dialect providers for OrmLite up to this point: