• I'm not entirely sure. Somewhere in the handshake the client tells sql which DB it wants to be in. You can try to test for the DB_ID() function, but I'm not sure that'll get you what you're after. I'd honestly have to play with it a little to see, but off the top of my head my guess is that it probably isn't going to get it. You can try it though. You might get lucky if the DB in question is the default DB for the acct.

    If you make it so that the acct can only access that one DB though, you'll be where you need to be.

    Another idea would be to setup a job every min to run through sysprocesses and check that nobody's running those SPs from a different app. This takes a little more coding, but you can use it to disable their accts and even send you an email with the relevant info. Then you can handle it on the human side as well by doing whatever it takes to make sure they don't do it again. I'd try the trigger approach first though.

    You know though, now that I think about it, there's another way to do this too. You can modify the SP to capture the App_Name() as well, and if it's not the app you want, just return. You'll use the same criteria you did in the trigger, only it'll be a check you run as soon as the SP kicks off. This is actually a pretty good one I think cause you can control it pretty well that way. Of course if you have 300 SPs to do this with you'll be busy, but what can I tell you...

    Watch my free SQL Server Tutorials at:
    http://MidnightDBA.com
    Blog Author of:
    DBA Rant – http://www.MidnightDBA.com/DBARant

    Minion Maintenance is FREE: