Configure database mode
Describes database mode configuration.
Optimizely Content Management System (CMS) supports two database modes: ReadWrite for normal operation and ReadOnly for maintenance or failover scenarios where the database accepts reads only. Choose the mode that matches your operational state.
ReadWrite
ReadWrite is the default mode. The application reads from and writes to the database normally.
ReadOnly
In ReadOnly mode, the application loads data from the database but does not save or update. Save and update operations through EPiServer.Data.IDatabaseExecutor throw exceptions, so CMS disables or alters the following modules and functions:
- CMS disables the Scheduler Service.
- CMS disables model sync.
- CMS disables content indexing.
- CMS disables user, role, and claims sync.
- Automatic database updates throw an exception when an update is required.
- CMS disables the statistics logger.
- CMS does not save
web.configto the database.
Configure the database mode
Configure the database mode through the databaseMode attribute on the episerver.dataStore section or the episerver:DatabaseMode setting in the appSettings section. The appsettings.json source is preferred in CMS 13. The XML examples apply to legacy configurations.
The following appsettings.json example sets ReadOnly mode:
{
"EpiServer": {
"Cms": {
"DataAccess": {
"DatabaseMode": "ReadOnly"
}
}
}
}The following episerver.dataStore example sets ReadOnly mode:
<episerver.dataStore databaseMode="ReadOnly"></episerver.dataStore>The following appSettings example sets ReadOnly mode:
<appSettings>
<add key="episerver:DatabaseMode" value="ReadOnly" />
</appSettings>Detect the database mode in code
Use IDatabaseMode to detect the current database mode in code:
ServiceLocator.Current.GetInstance<IDatabaseMode>().DatabaseModeAccess protected modules in ReadOnly mode
By default, CMS throws an HttpException with status code 503 when a request accesses a protected module in ReadOnly mode. Override this behavior by handling the AccessPath event.
ServiceLocator.Current.GetInstance<IAccessReadOnlyProtectedModules>().AccessPath += (object sender, ReadOnlyProtectedModuleEventArgs e) =>
{ e.Handled = true; // Put your code here redirect to a custom readonly page… }Updated about 9 hours ago
