transaction method

Begins a transaction for the specified object stores.


var retVal = IDBDatabase.transaction(storeNames, mode);


storeNames [in]

Type: any

If specified, defines the names of the object stores included in the transaction. Use a DOMString to specify a single object store or an array of DOMString values to specify multiple object stores.

mode [in, optional]

Type: DOMString


Changes are not allowed in this transaction.


Changes are allowed in this transaction.


Objects in the database can be created.



This method can throw the following DOMException exceptions:

Note  As of a Windows Store app using JavaScript, the code property is deprecated in favor of the name property, which is preferred for standards compliance and future compatibility.
Exception propertiesCondition
name: InvalidAccessError
code: DOMException.INVALID_ACCESS_ERR (15)

The value of the storeNames parameter is blank or otherwise invalid.

name: InvalidStateError
code: DOMException.INVALID_STATE_ERR (11)

The database has been closed or a transaction has been request for an object that has been deleted or is otherwise unavailable.

name: NotFoundError
code: DOMException.NOT_FOUND_ERR (8)

A specified object store could not be found in the current database (case-sensitive).

name: TypeError

The value of the mode parameter is not supported.


Standards information


While read-only and read/write transactions can be initiated with the transaction method, version change transactions occur only within the context of an upgradeneeded event, which can only be triggered by opening a database with a higher version number. For more info, see open.


The following example uses the transaction method to open an object store to a set of records and then calls a function with the cursor matching those records. For more info, see Managing data with transactions.

  if ( hIxHandle == null ) {
     handleError( "Can't open database (invalid handle)." );
  } else
       try {

          sObjectStore = getCardStoreName();        
          var hTransaction = hDBHandle.transaction( sObjectStore, "readonly" );
          var hObjectStore = hTransaction.objectStore( sObjectStore );
          var hRequest = hObjectStore.openCursor( aValue );
          hRequest.onerror = handleErrorEvent( evt );
          hRequest.onsuccess = function( evt ) {
             if ( fnCallback != null ) {
                var oResult = null; // assume no result.
                if ( != null ) {
                   oResult =; 
                doSomething( oResult );          
       } catch( ex ) {
         handleError( ex.message );

See also




© 2017 Microsoft