Here is some code i'm using:
Code: Select all
TransactionOptions options = new TransactionOptions();
options.IsolationLevel = IsolationLevel.ReadUncommitted;
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
{
try
{
con.Open();
con.EnlistTransaction(Transaction.Current);
user = System.Web.Security.Membership.CreateUser(this.NewCustomerConfirmEmail.Text.Trim(), this.Password.Text, this.NewCustomerConfirmEmail.Text.Trim());
System.Web.Security.Roles.AddUserToRole(user.UserName, "Customer");
MySqlCommand updatecust = new MySqlCommand("Update Customer set `First Name` = :FirstName, `Last Name` = :LastName, UserID = :UserID where CustomerID = :CustomerID", con);
updatecust.Parameters.Add("FirstName", MySqlType.VarChar); updatecust.Parameters[0].Value = NewCustomerFirstName.Text;
updatecust.Parameters.Add("LastName", MySqlType.VarChar); updatecust.Parameters[1].Value = NewCustomerLastName.Text;
updatecust.Parameters.Add("UserID", MySqlType.VarChar); updatecust.Parameters[2].Value = user.ProviderUserKey.ToString();
updatecust.Parameters.Add("CustomerID", MySqlType.VarChar); updatecust.Parameters[3].Value = CustomerID;
var reslt3 = updatecust.ExecuteNonQuery();
}
Code: Select all
user = System.Web.Security.Membership.CreateUser(this.NewCustomerConfirmEmail.Text.Trim(), this.Password.Text, this.NewCustomerConfirmEmail.Text.Trim());
System.Web.Security.Roles.AddUserToRole(user.UserName, "Customer");
I think I understand why the first problem is occurring. I want to execute creating a user and updating the customer userid column to the created user to execute as a transaction. But these two statements are in different transactions because there is no way to set or get the transaction that the membership class is using.
However, the second problem I can't wrap my head around. I thought transactions locked rows not the entire table? It seems if I execute the above code, it will time out and fall into the finally statement of my try/catch. In here it will call scope.dispose() but mysql locks up even after this is called not letting anyone read from the aspnet_membership or at least thats what I'm being told by users.
Can you help me understand what is going on? I'm not sure if it is the membership provider class or if there is another way to set the transaction that I'm not thinking about.