Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Why doesn't this work in code??
Message
De
13/11/2007 16:04:11
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Titre:
Why doesn't this work in code??
Divers
Thread ID:
01268744
Message ID:
01268744
Vues:
58
I am trying to create a method that determines if a user is part of the sysadmin group in order to determine if that user can create a database.

I can run the following Query in SQL Server Manager Studio and it produces multiple rows (some of which I've displayed below):

exec sp_helpsrvrolemember

sysadmin sa 0x01
sysadmin BUILTIN\Administrators 0x01020000000000052000000020020000
sysadmin NT AUTHORITY\SYSTEM 0x010100000000000512000000


But when I try to run the following code I only get one row (the first above). Any ideas?

SqlCommand cmd = new SqlCommand("sp_helpsrvrolemember", MyConnection);
cmd.CommandType = CommandType.StoredProcedure;

SqlDataReader rd = cmd.ExecuteReader(CommandBehavior.CloseConnection);

string Role;
string MemberName;

while (rd.Read())
{
Role = (string)rd["ServerRole"];
Role = Role.Trim().ToLower();

MemberName = (string)rd["MemberName"];
MemberName.Trim().ToLower();

if (Role == "sysadmin" && MemberName.Contains(username))
return true;
}

Thanks in advance.

Bob
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform