MS SQL Server 2008R2, "Login failed for user" from time to time, IIS 7 , NET 4.0
The clue is this


  Cannot open database "TheDatabase" requested by the login


This means that some connection string has either a non-existent database mentioned, or the login used does not have access. It is also possible that no database is mentioned, and the default database for the login is missing/no permission.

One of these 3 options is usually the answer...

Edit: you don't have auto-close on the database, do you?