Binding user-created temporary databases to a data cache

Use sp_bindcache to bind a database to a data cache. Binding a user-created temporary database is similar to binding any other user database, except in the following:

A user-created temporary database is considered to be in use as long as a session is assigned to it, even if no activity is actually taking place on behalf of the active session. However, to change the cache binding of the database, the database must be exclusively locked. You cannot lock the database as long as there is an active session assigned to it. The steps to overcome this are similar to those necessary to drop a database:

StepsChanging the cache binding of a database

  1. Use sp_tempdb to remove all bindings involving the temporary database, including any database-to-default-group bindings as well as any application and login bindings to the database.

  2. Either wait for any active sessions already assigned to the temporary database to drain out, or terminate these sessions if required. Use sp_tempdb to list the active sessions that are assigned to the database.

  3. Proceed with the database to cache binding.

  4. Restore any bindings removed in the first step.