Test-SPContentDatabase: Cannot open database [Database Name] requested by the login. The login failed.

Problem: 
In a SharePoint 2013 to SharePoint 2016 migration, I got this error message on testing the content database with Test-SPContentDatabase cmdlet  to identify possible issues:
“Cannot open database [Database Name] requested by the login. The login failed”

Test-SPContentDatabase: Cannot open database [Database Name] requested by the login. The login failed.

Troubleshooting:

  • If your databases are hosted on a different SQL Server or instance, other than the default SharePoint database server as its config database: Use -ServerInstance parameter with Test-SPContentDatabase cmdlet, because SharePoint always tries to find the database on the default database server. E.g.
    Test-SpContentDatabase -name "WSS_Content_KM_New" -webapplication https://portal.crescent.com -ServerInstance "SQL001\SharePoint"
  • Test-SPContentDatabase is running from the context of the SharePoint Farm Administrator account. So make sure the Farm Account has enough access to the content database! Go to SQL Server >> Security >> Under Logins right-click on your Farm Admin Account and select Properties. Under “User Mapping” tab >> Select your SharePoint content database >> Check the db_owner role.
  • Try running the PowerShell as an administrator.

If you get this “Cannot open database ‘Database Name’ requested by the login. The login failed” issue in case of orphaned databases. Follow this article to fix it: Cannot open database ‘WSS_Content’ Requested by the login. The login failed.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *