---
title: Configure database mode
slug: cms-13/docs/configure-database-mode
docTags: 
createdAt: 2026-07-30T20:22:10.689Z
---

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.config` to 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:

```json
{
  "EpiServer": {
    "Cms": {
      "DataAccess": {
        "DatabaseMode": "ReadOnly"
      }
    }
  }
}
```

The following `episerver.dataStore` example sets `ReadOnly` mode:

```xml
<episerver.dataStore databaseMode="ReadOnly"></episerver.dataStore>
```

The following `appSettings` example sets `ReadOnly` mode:

```xml
<appSettings>
  <add key="episerver:DatabaseMode" value="ReadOnly" />
</appSettings>
```

## Detect the database mode in code

Use `IDatabaseMode` to detect the current database mode in code:

```csharp
ServiceLocator.Current.GetInstance<IDatabaseMode>().DatabaseMode
```

## Access 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.

```csharp
ServiceLocator.Current.GetInstance<IAccessReadOnlyProtectedModules>().AccessPath += (object sender, ReadOnlyProtectedModuleEventArgs e) =>
  { e.Handled = true; // Put your code here redirect to a custom readonly page… }
```
