Tuesday, 17 August 2010

Run several N2CMS websites on one database server

One of the things that I have found is that out of the box, N2CMS will create your tables as:-
  • n2item
  • n2ContentItem etc.
Now, for some smaller clients of ours they can't afford to have a dedicated database server. On some of the cheaper hosts you can one database but then you'd need to create separate n2cms tables for each client.

It's dead simple to do this. If you had ClientA and ClientB you would want your tables to be something like:
  • ClientA_Item
  • ClientA_ContentItem and 
  • ClientB_Item
  • ClientB_ContentItem
To do this, look in your web.config and there's an element that you need to ammend

<!-- Other flavours: SqlServer2005, SqlServer2000, MySql, SqLite, SqlCe, Firebird -->
<database connectionStringName="N2CMS" flavour="AutoDetect" caching="true" cacheProviderClass="NHibernate.Caches.SysCache2.SysCacheProvider, NHibernate.Caches.SysCache2" tablePrefix="TheNameOfYourClient_">
<hibernateProperties>
<add name="hbm2ddl.keywords" value="none" />
</hibernateProperties>
</database>

Voila! You can now run several sites on one database!

Note: I always add a "_" after the name of the client as it makes the tables in the database look a little neater!

2 comments:

  1. Did you mean..

    ClientA_Item
    ClientA_ContentItem and
    ClientB_Item
    ClientB_ContentItem

    ..?

    ReplyDelete
  2. Yes - I've updated the article :) Thanks for pointing that out.

    ReplyDelete