Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 581971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:38:12+00:00 2026-05-13T14:38:12+00:00

Is it possible to change execution context to CALLER in a stored procedure, which

  • 0

Is it possible to change execution context to CALLER in a stored procedure, which is created with EXECUTE AS OWNER? Here is what I mean with a simplified example:

There are several logins and databases in a server instance. Assume that everybody has a table named current_work in his own database, but nobody can access to no other’s table. Even the Boss isn’t allow to access to the employees’ databases, unless an employer decides that his table is ready for the Boss to see. When the employer thinks his work is done, he is supposed to commit its table contents to Boss’ database. However, the Boss doesn’t want to allow his employers to INSERT anything into his table, because there is a kind of business logic he wants to implement (let’s say he wants to log the commits somewhere). So he wants this to happen only under his control, i.e. within an SP he wrote. He writes an SP like below, creates users in his database for each of the logins (for each employee), and then gives GRANT EXECUTE for this SP to all his employers. When an employee is done, he just calls this SP, and everything should be fine:

CREATE PROCEDURE boss.dbo.commit_work
WITH EXECUTE AS OWNER AS
BEGIN
   EXECUTE AS CALLER  -- It should be OK, since this is the default way of calling an SP anyway, thinks the boss
   SELECT * INTO ##tmptable FROM current_work  -- No prefix should mean default DB/Schema of the caller, thinks the boss
   REVERT  -- Back to OWNER's context, which happens to be the boss

   INSERT INTO boss.allwork
   SELECT * FROM ##tmptable
END

However, things doesn’t go as he expected. The employers can execute the SP, but they get an error saying ‘The server principal “Boss” is not able to had access the database “boss” under the current security context.’, which makes the boss very upset (BTW Boss is the Login for the boss.)

Do you have an idea of what went wrong? Or do you see another way of implementing such a scenario, in which nobody is supposed to access to no other’s DB unless the execution happens in the SP? I would have done such a thing in application level, when I had had the choice, but I am bound to database level because of the requirements of our current environment. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:38:13+00:00Added an answer on May 13, 2026 at 2:38 pm

    I found the answer here in this great article of Erlang Sommarskog “Giving Permissions through Stored Procedures”. I recommend you to read the whole article to grasp the idea.. All I had to do was creating a local proxy user and giving it the appropriate rights:

    CREATE USER boss_proxy WITHOUT LOGIN
    GRANT INSERT ON boss.allwork TO boss_proxy 
    
    CREATE PROCEDURE boss.dbo.commit_work
    WITH EXECUTE AS boss_proxy AS
    BEGIN
       EXECUTE AS CALLER  -- It IS OK, indeed
       SELECT * INTO ##tmptable FROM current_work  -- No prefix means default DB/Schema of the caller
       REVERT  -- Back to boss_proxy's context
    
       INSERT INTO boss.allwork
       SELECT * FROM ##tmptable
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Change CSS Dynamically I need to change the height of a div
Is it possible to change the width of a scroll bar on a form.
Is it possible to change the font size used in a ContextMenu using the
Is it possible to change a Sharepoint 2007 Site Theme through a Web Service?
Is it possible to change the frame title when using \againframe from the Beamer
Is it possible to change the auto-increment offset on a pre-existing table with JavaDB?
Is it possible to change the connection string of a bound dataset during runtime?
I know it's possible to change some columns in GridView controls to check boxes
I was wondering if it was possible to change the my Shoes app's icon?
Is it possible to to change a <span> tag (or <div> ) to preformat

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.