Microsoft® SQL Server™ encountered an error while attempting to initiate a read or write request. This error can occur for any of the following reasons:
A database file is off-line.
A database file has been removed or renamed.
A database file is inaccessible for another reason (such as insufficient permissions).
The parameter in the error message refers to an internal structure and does not help determine which database file is involved. However, other error messages appearing in the error log just before error 822 usually indicate the file involved.
CAUSE
SQL Server caches index IDs in the compiled plan. However, the stored procedure can be such that for a different invocation this cached index ID belongs to a different index on the local temporary table. A check for sharing and reusing plans does not seem to catch this, and SQL Server uses the old plan for this invocation. In addition, auto-create and auto-drop statistics that are used in the query plan do not keep track of the temporary table, which results in the errors.