Configuring the Database

N2 supports several kinds of databases.

  •  Relational Database

  •  XML Data Store

  •  NoSQL Database

Installing Database Drivers

You may need to install a database driver in order to enable accessing a particular type of database. For example,

  • if you want to use SQLite relational database, you should install the N2CMS.SQlite.X86 NuGet package (which in turn installs System.Data.SQLite). 

If you want to use the built-in XML data store, no additional database driver is required. 

Using a Relational Database

To configure a relational database open web.config in the site’s root directory and find the <connectionStrings> section.

<!-- Please not that you need to configure another database and remove \bin\system.data.sqlite.dll if you run in medium trust -->
<add name="N2CMS" connectionString="Data Source=|DataDirectory|\n2.sqlite.db;Version=3;New=True;" providerName="System.Data.SQLite" />

Then replace the connection string tag with one that corresponds to the database engine you want to use.

Database EngineConnection String
SQLite

<add name="N2CMS" connectionString="Data Source=|DataDirectory|\n2.db;Version=3;New=True;" providerName="System.Data.SQLite"/>

SQL Server 2005+

<add name="N2CMS" connectionString="Server=(local);Database=N2_Templates;Integrated Security=SSPI"/>

SQL Express 2005+

<add name="N2CMS" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\N2.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>

SQL Server 2000

<add name="N2CMS" connectionString="Data Source=SQLServer2000;Database=SQLDatabase2000;User Id=SqlUser2000;Password=SqlPassword2000;Network Library=DBMSSOCN;" providerName="System.Data.SqlClient"/>

MySQL

<add name="N2CMS" connectionString="Data Source=MySQLServer;Database=MySQLDatabase;User Id=MySQLUser;Password=MySQLPassword;" providerName="MySql.Data.MySqlClient"/>

N2 supports several kinds of databases. To configure another database open web.config in the site’s root directory and find the <connectionStrings> section. Remove the existing connection string and update the most relevant template to your database’s settings. 

XML Data Store

Coming soon! N2CMS supports storing your data as loose XML files on disk. This avoids the need to load any database drivers, which in some cases can reduce your site's memory footprint and improve performance.

<n2>
    <database flavour="Xml" caching="true"></database>
</n2>

NoSQL Data Store

Coming soon! N2CMS supports NoSQL databases such as MongoDB. N2CMS can be extended to support other NoSQL systems as well. 

To configure MongoDB:

 

Switching Databases After Installation

You can change the database type after installing N2. To do this we recommend that you first export all your site data and users from N2 using the Bulk > Export functionality, then switch database engines and re-enable installation by setting allowInstallation="true" and modifying the connection string in web.config. Then navigate to your site and in the setup wizard, after creating tables opt to import the .xml file that you just exported. N2 will recreate the database entities for your data in the new database.