Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why doesn't this work in code??
Message
From
13/11/2007 16:04:11
 
 
To
All
General information
Forum:
ASP.NET
Category:
Databases
Title:
Why doesn't this work in code??
Miscellaneous
Thread ID:
01268744
Message ID:
01268744
Views:
57
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
Next
Reply
Map
View

Click here to load this message in the networking platform