“Cannot open database ‘…’ requested by the login. The login failed” or “The EXECUTE permission was denied on the object ‘…’, database ‘…’, schema ‘dbo’”

  • Sandro Pereira
  • Feb 29, 2012
  • 3 min read

It’s very common for orchestrations to access databases or execute stored procedures. Whether this access is done by SQL Adapter, WCF-SQL adapter, or through C # code, if we are not careful to set the user permissions properly in the database, we can get one of these errors:

Cannot open database ‘…’ requested by the login. The login failed

or:

The EXECUTE permission was denied on the object ‘…’, database ‘…’, schema ‘dbo’

📝 One-Minute Brief

This troubleshooting guide solves the common SQL Server permission errors encountered when BizTalk Server or a .NET application attempts to access a database. It covers two scenarios: failing to open the database due to incorrect login mappings and the “EXECUTE permission denied” error when calling stored procedures. Sandro explains how to resolve these by correctly mapping users to database roles and granting specific execution rights to the db_owner or custom roles.

Cause

This problem occurs because the user account that you used to access the database or that tries to execute the stored procedure does not have sufficient permissions.

Solution

You need to grant permission to the user to access the database and/or to execute the stored procedure.

Normally, orchestrations are running under the BizTalk Application Users group, but you have to check the Windows group configured on the host instance that runs the orchestrations that want to access the database.

How to grant reader/writer access to SQL database:

  • In SQL Server Management Studio, open Object Explorer and expand it to the database that you want to give access to.
  • Right-click the Security folder, point to New, and then click User.
SQL Add User login
  • On the General page, enter your username and log in in the Login name box.
  • Set the following Database role membership:
    • db_datareader
    • db_datawriter
How grant reader writer access SQL database
  • Click OK.

Granting execute permissions to all stored procedures in a database:

  • In SQL Server Management Studio, open Object Explorer and expand it to the database that you want to give execute access to.
  • Right-click the database name and then click Properties.
  • In the Permissions tab
    • Select the user inthe Users or roles panel
    • And on Permissions for the user panel, check the grant for the Execute permission.
Granting execute permissions to all stored procedures in database
#1 Azure Monitoring Platform

Hope you find this helpful! If you liked the content or found it useful and would like to support me in writing more, consider buying (or helping to buy) a Star Wars Lego set for my son. 

Thanks for Buying me a coffe
Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.

5 thoughts on ““Cannot open database ‘…’ requested by the login. The login failed” or “The EXECUTE permission was denied on the object ‘…’, database ‘…’, schema ‘dbo’””

  1. Hello There. I found your blog the use of msn. That is a very well written article. I’ll make sure to bookmark it and return to read more of your useful info. Thanks for the post. I will certainly comeback.

  2. Hi,
    These common SQL Server errors usually occur when user accountor permissions are not configured properly. The first error, Cannot open database requested by the login, indicates that the login doesn’t have access to the specified database. The second error, The EXECUTE permission was denied, points to missing execute rights on a stored procedure or function. Both issues can be fixed by granting the required permissions or assigning the correct database role.

Leave a Reply

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

The Ultimate Cloud
Management Platform for Azure

Supercharge your Azure Cost Saving

Learn More
Turbo360 Widget

Back to Top