files/en-us/web/api/idbdatabase/close/index.md
{{ APIRef("IndexedDB") }} {{AvailableInWorkers}}
The close() method of the {{domxref("IDBDatabase")}}
interface returns immediately and closes the connection in a separate thread.
The connection is not actually closed until all transactions created using this connection are complete. No new transactions can be created for this connection once this method is called. Methods that create transactions throw an exception if a closing operation is pending.
close()
None.
None ({{jsxref("undefined")}}).
// Let us open our database
const DBOpenRequest = window.indexedDB.open("toDoList", 4); // opening a database.
// Create event handlers for both success and failure of
DBOpenRequest.onerror = (event) => {
note.appendChild(document.createElement("li")).textContent =
"Error loading database.";
};
DBOpenRequest.onsuccess = (event) => {
note.appendChild(document.createElement("li")).textContent =
"Database initialized.";
// store the result of opening the database in the db variable.
db = DBOpenRequest.result;
// now let's close the database again!
db.close();
};
{{Specifications}}
{{Compat}}