Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2004
    Posts
    27

    Unanswered: Change the active user in sp

    Hello,
    I would like to change the active user in a stored procedure
    Ex. :
    I'm logged on sql as "userA".
    I call the stored procedure "spGetInfo".
    In the first line of "spGetInfo" I would like to do something like "su poweruser", query some data and do "su system_user"

    Is there anything like the unix "su" command in SQL ?

    Thank a lot

    Felix Pageau
    fpageau@SPAMSUCK.str.ca

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I'm not quite sure what you are asking. Assuming that the user has the permission to execute a stored procedure, that stored procedure executes in the security context of the user that CREATES the procedure. If the dbo creates a procedure, the procedure can do anything that the dbo can do when any user runs it.

    The only exception is that dynamic SQL always runs in the context of the currently logged in user. That can hang you up, but otherwise you should be fine.

    -PatP

  3. #3
    Join Date
    Jan 2004
    Posts
    27
    Hello,

    my problem is that the stored procedure contain dynamic sql. I need to execute the dynamic sql query without giving the user to query the table.

    I thought that with a kind of "impersonation" I would be able to do so but I haven't found any.

    Do you know a way to execute dynamic sql in another context than then one of the user that has called the sp ?

    Thank for your reply

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    The quickest and easiest answer is probably an extended stored procedure. I don't know of anything in Transact-SQL that will allow you to do that.

    -PatP

  5. #5
    Join Date
    Jan 2004
    Posts
    27
    Do you mean I should create an extended sp with my sql code or that I should call an existing extend sp ???

  6. #6
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    If you need to "switch context" to allow dynamic SQL to execute, I'm suggesting that you write an extended stored procedure that allows you to control what gets executed and how. I don't know of a way to get you what you want using just Transact-SQL.

    -PatP

  7. #7
    Join Date
    May 2002
    Location
    Timbaktu
    Posts
    185
    Even if you change the user inside your stored procedure from simple user to system admin user, the proc would still be running under the simple user access rights.
    Best would be to define the access rights using the role, stored procedure etc etc and then control the sql.

    Unix and SQL are entirely two different world.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •