What things should I consider when choosing between database roles and application roles in SQL Server?
I understand how each type of role works, but I'm struggling to understand when an application role would be appropriate to use over a database role.
Up until now, I've just used database roles in my application. I've basically created an account for each user and then assigned them to whatever roles they need access to using GRANT
statements. The application in question is just a simple data-entry/reporting application.
Would there be any benefit on using application roles and if so, how do I go about using them? Specifically how do I ensure that a given user cannot access objects they shouldn't be able to. Do I need multiple application roles or is there some other way?
The stated purpose of application roles is to attach a set of security to a 'application'. The idea being that the approle password is only known to the application, and is actually defined within it (in a suitably obfuscated way)
If you have a user with a fixed database security levels that needs different security levels when using a particular application then you might want to use an application role. Otherwise don't bother
For example Joe logs into the database using his database credentials but should only read (not change) data in a table
Joe uses the same database through the financial application. The application happens to connect using the same credentials (Joe)
However through the application he also needs to be also allowed to insert/update a table.
In this case you would use an application role to override Joe's security by calling sp_setapprole in the application
(Joe could could actually call this sp himself if he knew what the password was... but he shouldn't know it)
The application would have some validation in the front end stopping him doing silly things to the data.
It's a very specific case.