Cannot open database ‘WSS_Content’ Requested by the login. The login failed.
In a SharePoint 2007 environment, All of a sudden, all custom applications which use server object model, started failing with an error: Cannot open Database WSS_Content_SharePoint_DB requested by the login. The login Failed. Login failed for user <domain\user_account>
Root cause:
There was an old unused site collection’s content database attached with the web application. Since the particular site collection was no longer needed, SharePoint Administrator just deleted the database during a maintenance window from SQL Server.
But SharePoint configuration was still referring the database and trying to connect! This error got logged multiple times in event log also. So the right sequence would be:
- Delete the content database from SharePoint first (stsadm -o deletecontentdb or using Central Administration)
- Then delete the database from SQL Server.
This error may appear when there is a permission issue and can be resolved by either granting access to the service account or changing the SharePoint Timer service’s identity to the account which has enough privileges on the databases, which is described here: Event ID 3351: SQL database login failed
Cannot open database ‘db_name’ Requested by the login Error in SharePoint 2013:
The same issue happened in SharePoint 2013, with Event ID: 3760
SQL Database “db_name” on SQL Server instance “sql_instance_name” not found. Additional error information from SQL Server is included below.
Cannot open database “db_name” requested by the login. The login failed. Login failed for user ‘domain\login’.
Solution: Remove the deleted Database reference from SharePoint using PowerShell:
Get-SPDatabase | where {$_.name -eq 'db_name'} | foreach {$_.Delete()};
Thanks for your post. It helped me in fixing my issue.