Roles.AddUserToRole Fails

May 1, 2009 at 4:06 AM
I am using NetSqlAzMan version 3.5.4, and this is broken in 3.5.2.1 as well.

I am using the SQL Membership provider for my users.

I am trying a simple test to create a db user and then add that user to a role. I get an exception as shown below.
This code worked on version 2.4.X


 

string name = "pip";

 

 

string pw = "abc123#";

 

 

MembershipUser msu = null;

 

 

if (!Membership.ValidateUser(name, pw))

 

{

 

if (Membership.RequiresQuestionAndAnswer)

 

{

 

MembershipCreateStatus memberstatus;

 

msu =

Membership.CreateUser(name, pw, "me@you.com", "what up", "nuttin", true, out memberstatus);

 

}

 

else

 

{

msu =

Membership.CreateUser(name, pw);

 

}

 

if (!Membership.ValidateUser(name, pw))

 

{

 

MessageBox.Show("User does not Exist");

 

}

}

msu =

Membership.GetUser(name);

 

 

if (!Roles.RoleExists("DaMan"))

 

{

 

Roles.CreateRole("DaMan");

 

}

 

if (!Roles.IsUserInRole(name,"DaMan"))

 

{

 

Roles.AddUserToRole(name, "DaMan");

 

}



EXCEPTION ***********************************

"ExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction.  The Transaction property of the command has not been initialized."

at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean async)

at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)

at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)

at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)

at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)

at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)

at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)

at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)

at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)

at NetSqlAzMan.LINQ.NetSqlAzManStorageDataContext.GetDBUsersEx(String storeName, String applicationName, Byte[] dBUserSid, String dBUserName)

at NetSqlAzMan.SqlAzManApplication.GetDBUser(String userName)

at NetSqlAzMan.Providers.NetSqlAzManRoleProvider.AddUsersToRoles(String[] usernames, String[] roleNames)

at System.Web.Security.Roles.AddUserToRole(String username, String roleName)

at JSDSecureTestApp.Form1.btnTestIt_Click(Object sender, EventArgs e) in C:\JSD\IDA\trunk\Source Code\JSDTools\JSDSecureTestApp\Form1.cs:line 94


END EXCEPTION ***********************************



My Configuration Files are:

 

<

 

roleManager defaultProvider="NetSqlAzManRoleProvider" enabled="true" >

 

<

 

providers>

 

<

 

clear/>

 

<

 

add name="NetSqlAzManRoleProvider" type="NetSqlAzMan.Providers.NetSqlAzManRoleProvider, NetSqlAzMan"

 

 

connectionStringName="MyAspNetDB"

 

 

storeName="JSD"

 

 

applicationName="IDA"

 

 

userLookupType="DB"

 

 

defaultDomain=""/>

 

</

 

providers>

 

</

 

roleManager>

 

<

 

membership defaultProvider="SqlMembershipProvider">

 

<

 

providers>

 

<

 

clear/>

 

<

 

add name="SqlMembershipProvider"

 

 

connectionStringName="MyAspNetDB"

 

 

enablePasswordRetrieval="false"

 

 

enablePasswordReset="true"

 

 

requiresQuestionAndAnswer="true"

 

 

applicationName="/IDA"

 

 

requiresUniqueEmail="false"

 

 

passwordFormat="Hashed"

 

 

maxInvalidPasswordAttempts="5"

 

 

minRequiredPasswordLength="7"

 

 

minRequiredNonalphanumericCharacters="1"

 

 

passwordAttemptWindow="10"

 

 

passwordStrengthRegularExpression=""

 

 

type="System.Web.Security.SqlMembershipProvider" />

 

</

 

providers>

 

</

 

membership>

 

May 1, 2009 at 5:18 AM
I did a little more testing and I have narrowed it down to this call in 

 

public override void AddUsersToRoles(string[] usernames, string[] roleNames)

 


NetSqlAzMan.Interfaces.

IAzManSid sid = application.GetDBUser(username).CustomSid;

Brian

 

May 1, 2009 at 8:15 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.