Locking and Unlocking Databases (XMLA)

You can lock and unlock databases using, respectively, the Lock and Unlock commands in XML for Analysis (XMLA). Typically, other XMLA commands automatically lock and unlock objects as needed to complete the command during execution. You can explicitly lock or unlock a database to perform multiple commands within a single transaction, such as a Batch command, while preventing other applications from committing a write transaction to the database.

Locking Databases

The Lock command locks an object, either for shared or exclusive use, within the context of the currently active transaction. A lock on an object prevents transactions from committing until the lock is removed. Microsoft SQL Server SQL Server Analysis Services supports two types of locks, shared locks and exclusive locks. For more information about the lock types supported by SQL Server Analysis Services, see Mode Element (XMLA).

SQL Server Analysis Services allows only databases to be locked. The Object element must contain an object reference to an SQL Server Analysis Services database. If the Object element is not specified or if the Object element refers to an object other than a database, an error occurs.

Important

Only database administrators or server administrators can explicitly issue a Lock command.

Other commands implicitly issue a Lock command on an SQL Server Analysis Services database. Any operation that reads data or metadata from a database, such as any Discover method or an Execute method running a Statement command, implicitly issues a shared lock on the database. Any transaction that commits changes in data or metadata to an object on an SQL Server Analysis Services database, such as an Execute method running an Alter command, implicitly issues an exclusive lock on the database.

Unlocking Objects

The Unlock command removes a lock established within the context of the currently active transaction.

Important

Only database administrators or server administrators can explicitly issue an Unlock command.

All locks are held in the context of the current transaction. When the current transaction is committed or rolled back, all locks defined within the transaction are automatically released.

See Also

Lock Element (XMLA)
Unlock Element (XMLA)
Developing with XMLA in Analysis Services