Toggle Databases State Operation
(Enable / Disable)



Enable/Disable database from the Client API

Enable database:

// Define the toggle state operation
// specify the database name & pass 'false' to enable
const enableDatabaseOp = new ToggleDatabasesStateOperation("Northwind", false);

// To enable multiple databases use:
// const enableDatabaseOp =
//     new ToggleDatabasesStateOperation(["DB1", "DB2", ...], false);

// Execute the operation by passing it to maintenance.server.send
const toggleResult = await documentStore.maintenance.server.send(enableDatabaseOp);

Disable database:

// Define the toggle state operation
// specify the database name(s) & pass 'true' to disable
const disableDatabaseOp = new ToggleDatabasesStateOperation("Northwind", true);

// To disable multiple databases use:
// const disableDatabaseOp =
//     new ToggleDatabasesStateOperation(["DB1", "DB2", ...], true);

// Execute the operation by passing it to maintenance.server.send
const toggleResult = await documentStore.maintenance.server.send(disableDatabaseOp);

Syntax:

// Available overloads:
const enableDatabaseOp = new ToggleDatabasesStateOperation(databaseName, disable);
const enableDatabaseOp = new ToggleDatabasesStateOperation(databaseNames, disable);
Parameter Type Description
databaseName string Name of database for which to toggle state
databaseNames string[] List of database names for which to toggle state
disable boolean true - request to disable the database(s)
false- request to enable the database(s)

// Executing the operation returns an object with the following properties:
{
    disabled, // Is database disabled
    name,     // Name of the database
    success,  // Has request succeeded
    reason    // Reason for success or failure
}

Disable database via the file system

It may sometimes be useful to disable a database manually, through the file system.

  • To manually disable a database:

    • Place a file named disable.marker in the database directory.
    • The disable.marker file can be empty,
      and can be created by any available method, e.g. using the File Explorer, a terminal, or code.
  • Attempting to use a manually disabled database will generate the following exception:

     Unable to open database: '{DatabaseName}', 
     it has been manually disabled via the file: '{disableMarkerPath}'. 
     To re-enable, remove the disable.marker and reload the database.
    
  • To enable a manually disabled database:

    • First, remove the disable.marker file from the database directory.
    • Then, reload the database.