Getting database user from a database
As per requirement i need to get the information whether an user is present in given database or not. Whether there is any stored procedure which i can use to get this information of user. 开发者_如何学JAVAI just want to check whether user is present in given database, and proceed further with my usage.
I am using MSSQL Server 2005.
Also i need another information, there is on method LastErrorMessage() to get the last error message in ADO. is there any method to get the error number.
Thanks, Santhosha
SQL Server has logins (server level) and users (database level). Users are permissioned on databases/database objects and are mapped (well not neccessarily) to logins (roles are also at database level).
users are available from the sys.database_principals
system view in each database
logins are available from the sys.server_principals
You need to be aware that you can only see objects/principals which the user you are using to connect to SQL server has permission to see. So a user might exist, even if you don't see it in the views.
精彩评论