Note that there are some explanatory texts on larger screens.

plurals
  1. POThe right way to call the MembershipProvider methods?
    text
    copied!<p>On my CreateUserWizard, I'm invoking additional properties and when I call GetUser(), I receive:<br /><br /> <em>"There is already an open DataReader associated with this Command which must be closed first"</em> <br /><br />The codebehind of Registration.aspx:</p> <pre><code> NCCMembershipUser currentUser = (NCCMembershipUser)Membership.GetUser(); Guid id = (Guid)currentUser.ProviderUserKey; ...assigning control values to membership values... try { NCCMembershipProvider u = (NCCMembershipProvider)Membership.Provider; u.UpdateUser(currentUser); } </code></pre> <p>Should I not be using GetUser to access the properties?</p> <p>Here's the GetUser method:</p> <pre><code> public override MembershipUser GetUser(string username, bool userIsOnline) { SqlConnection conn = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand("SELECT UserID," + " Email," + " Comment," + " PasswordQuestion," + " IsApproved," + " LastActivityDate," + " LastLoginDate," + " LastPasswordChangedDate," + " CreationDate," + " IsLockedOut," + " LastLockedOutDate," + " UserSalutation," + " UserFirstName," + " UserLastName," + " UserPosition," + " UserCompany," + " UserCompanyType," + " UserCompanyTypeOther," + " UserAccountType," + " UserAddress1," + " UserAddress2," + " UserCity," + " UserStateProv," + " UserPostal," + " UserCountry," + " UserWebsite," + " UserPhone," + " UserPhoneExt," + " UserFax," + " UserIP," + " UserIPLastLogin," + " IsSubscribed," + " LikeAreaRugs," + " LikeCarpeting," + " LikeCoverings," + " LikeComponents," + " LikeHotel," + " LikeAccessories" + " FROM Users WHERE Email = @Email AND ApplicationName = @ApplicationName", conn); cmd.Parameters.Add("@Email", SqlDbType.NVarChar, 128).Value = username; cmd.Parameters.Add("@ApplicationName", SqlDbType.NVarChar, 255).Value = m_ApplicationName; NCCMembershipUser u = null; SqlDataReader reader = null; try { conn.Open(); reader = cmd.ExecuteReader(); if (reader.HasRows) { reader.Read(); u = GetUserFromReader(reader); if (userIsOnline) { SqlCommand updateCmd = new SqlCommand("UPDATE Users " + "SET LastActivityDate = @LastActivityDate " + "WHERE Email = @Email AND ApplicationName = @ApplicationName", conn); updateCmd.Parameters.Add("@LastActivityDate", SqlDbType.DateTime).Value = DateTime.Now; updateCmd.Parameters.Add("@Email", SqlDbType.VarChar, 255).Value = username; updateCmd.Parameters.Add("@ApplicationName", SqlDbType.VarChar, 255).Value = m_ApplicationName; updateCmd.ExecuteNonQuery();//&lt;&lt;------Error:"There is already an open DataReader associated with this Command which must be closed first." } } } catch (SqlException e) { if (WriteExceptionsToEventLog) { WriteToEventLog(e, "GetUser(String, Boolean)"); throw new ProviderException(exceptionMessage); } else { throw e; } } finally { if (reader != null) { reader.Close(); } conn.Close(); } return u; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload