Bug #60138 Update profile property create duplicate value entry, will not get latest value
Submitted: 16 Feb 2011 3:43 Modified: 16 Feb 2011 4:49
Reporter: Middle King Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:6.3.5 OS:Windows (Window 7 Pro - 64bits)
Assigned to: CPU Architecture:Any
Tags: MySQLProfileProvider

[16 Feb 2011 3:43] Middle King
Description:
I used the Business Application Template to create my application. using MySQLConnector .NET v6.3.5.

1. My User class:
 public partial class User : UserBase
 {
       [ProfileUsage(IsExcluded = true)]
       public Int32 UserID { get; set; }
       public string FriendlyName { get; set; }
       public string RTrackLineColor { get; set; }
 }
2. Web.config
<profile enabled="true" defaultProvider="MySQLProfileProvider">			<properties>				<add name="FriendlyName" />				<add name="RTrackLineColor" type="string" defaultValue="Green" />			</properties>
<profile enabled="true" defaultProvider="MySQLProfileProvider">
<properties>
<add name="FriendlyName" />
<add name="RTrackLineColor" type="string" defaultValue="Green" />
</properties>

3. Setting the property and saving:

WebContext.Current.User.RTrackLineColor = "value";          
WebContext.Current.Authentication.SaveUser(false);

Each time after saving, then log off and log in, the WebContext.Current.User.RTrackLineColor won't take the latest value set for the property but the first value set instead.

How to repeat:
This is my reported bug with RIA but it seems not the bug of RIA.

http://forums.silverlight.net/forums/t/219559.aspx

Suggested fix:
I user Red Gate Reflector to look into the MySql.Web.dll and found out here could have been causing the problem.

public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
{
...............
Should check the for Inserting or updating existing value for the index (profile property) here.
...............

 MySqlCommand command = new MySqlCommand("INSERT INTO my_aspnet_Profiles  \r\n                        VALUES (@userId, @index, @stringData, @binaryData, NULL) ON DUPLICATE KEY UPDATE\r\n                        valueindex=VALUES(valueindex), stringdata=VALUES(stringdata),\r\n                        binarydata=VALUES(binarydata)", connection);
                command.Parameters.Clear();
                command.Parameters.AddWithValue("@userId", num2);
                command.Parameters.AddWithValue("@index", index);
                command.Parameters.AddWithValue("@stringData", stringData);
                command.Parameters.AddWithValue("@binaryData", binaryData);
                if (command.ExecuteNonQuery() == 0)
                {
                    throw new Exception(Resources.ProfileUpdateFailed);
                }
                transaction.Commit();
            }
            catch (Exception exception)
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                }
                throw new ProviderException(Resources.ProfileUpdateFailed, exception);
            }
            finally
            {
                if (connection != null)
                {
                    connection.Dispose();
                }
            }
        }
    }
}
..........
}
[16 Feb 2011 4:49] Middle King
I found the problem caused by the previous schema tables created by the previous version of MySQL Connector. I tried created the schema table with 6.3.5 in VS2010 again then it run properly. The problem is the primary column (userid) of my_aspnet_profiles was not created.

Thanks,
middlevn