I want to check if the connected user is a SQL Server admin (in the sysadmin role) and wondering if this is this is the best way to do it?
private static bool IsUserAdmin(Server server)
{
Login login = server.Logins[server.ConnectionContext.Login];
return login.IsMember("sysadmin");
}
In SQL DMO (the COM based predecessor to SMO) there was a property that hung off the SQLDMO.SQLServer
object called IsServerAdmin
. I'm wondering if there's something similar in SMO but that I just haven't been able to find it?