2

I am working on a web application which uses Orchard CMS framework to leverage the modular,multi-tenant feature .I have multiple modules and all are working fine with the current SQL server DB(say DB1) which I have mentioned in the settings.txt file.Now I had requirement popped up in which one of my module need to talk to a different database(say DB2) other than the one mentioned in the settings.txt file.How this module alone will talk to the new database(DB2) keeping all the other modules contacting the DB1? How can I direct my FluentNHibernate in this module alone to use new database(DB2)?

RKURUNGAT
  • 21
  • 2

1 Answers1

1

If you just need to execute some SQL against the second database then you just need to suppress orchard's transaction like so:

const string connectionString = "...";
var connection = new SqlConnection(connectionString);

using (new TransactionScope(TransactionScopeOption.Suppress)) {
    connection.Open();
    ...
    connection.Close();
}
Hazza
  • 6,441
  • 3
  • 24
  • 37
  • As for where to store the connection string, not in `settings.txt`, which is reserved for those Orchard fundamental settings that can't be fetched from the database. In your case, your module's configuration settings will do fine (those are stored in the Orchard database, see existing modules for plenty of examples). – Bertrand Le Roy Apr 28 '19 at 17:39