Exit if it is wrong user

  • I am having a script which creates objects in a database i.e. it has create table, view etc. It should be run as say 'user1' and 'user1' is the dbo.

    But users usually make the mistake of running it as 'sa' and this spoils the purpose of it.

    How can I prevent it? I want to throw error and if possible EXIT SQLQuery Analyzer.

    The users always use SQLQuery Analyzer.

    Please give me a suggestion and I have not tried it in iSQL for the above mentioned reason.

    Thanks,

    NeoNash

  • Really you cannot do this except possibly with an application permission but have never tried so cannot say. I suggest change the SA password and not let anyone have it as they can cause a lot of damage with that kind of access anyway.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • I need to add the scenario.

    I generate the script for this application and my clients install on their database servers. So, the question is not the password control but its wrong usage.

  • Ok it is not the login problem but the fact they use the script under the sa login. Since it is a script then try this at the begining

    if SYSTEM_USER = 'sa'

    BEGIN

    RAISERROR('This script must be run from a user account, please exit and login the proper account.', 16, -1)

    RETURN

    END

    That is as close to what you state as I can see how to get.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply