I have a simple stored procedure which needs to check if the account name "DOMAIN\alex" specified as parameter is a valid account on that system. At least, valid enough to create a new login account for. I just can't find a simple function to do this in T-SQL and I don't want to write some .NET plugin or whatever. So, does anyone know which function I can use to validate the account name?
The purpose of this Stored Procedure is to check if Windows knows the account name before it's used to create a new login. This login is then linked to a database user with restricted access.
But to create the login, I need to make sure that the Windows account is an existing account, else the "CREATE LOGIN" will fail. (And I hate failing statements, which require exception handlers.)
Even if you solve your question, you're going to end up with lots of SQL logins. Difficult to control. They'll go stale when people leave. You'll have to change the permissions of all of them when changes are needed.
It would be much easier and better to do it like this:
Then you'll only have one SQL login and, if the permissions need to change, you just change the role's permissions and you're done.
answered Jan 29, 2010 at 11:58 AM
to find a login on a server use:
You can use
to test for its appearance and to then allow a process if it is or isnt found...
answered Jan 29, 2010 at 11:15 AM