Hi
I'm still a little new to DNN so bear with me... I have a requirement to add a custom property to a user's profile. Here's what I wrote to take the user account, test for the existence of the property and add it if necessary: -
Private Sub SetUserProperty(ByVal User As DotNetNuke.Entities.Users.UserInfo, ByVal PropertyName As String, ByVal Value As String)
Dim ProfileProperty As DotNetNuke.Entities.Profile.ProfilePropertyDefinition
ProfileProperty = User.Profile.ProfileProperties.GetByName(PropertyName)
If (ProfileProperty Is Nothing) Then
ProfileProperty = New DotNetNuke.Entities.Profile.ProfilePropertyDefinition
ProfileProperty.PortalId = _PortalSettings.PortalId
ProfileProperty.PropertyCategory = "BTS"
ProfileProperty.PropertyName = PropertyName
ProfileProperty.PropertyValue = Value
ProfileProperty.Length = 255
ProfileProperty.DataType = 349
ProfileProperty.Visibility = UserVisibilityMode.AllUsers
ProfileProperty.Visible = True
User.Profile.ProfileProperties.Add(ProfileProperty)
Else
User.Profile.SetProfileProperty(PropertyName, Value)
End If
ProfileProvider.UpdateUserProfile(User)
End Sub
This is the error I get: -
Error: BTS User Import is currently unavailable.
DotNetNuke.Services.Exceptions.ModuleLoadException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_UserProfile_ProfilePropertyDefinition". The conflict occurred in database "C:\LUKE\VISUAL STUDIO 2005\WEBSITES\DNN\APP_DATA\DATABASE.MDF", table "dbo.ProfilePropertyDefinition", column 'PropertyDefinitionID'. The statement has been terminated. ---> System.Data.SqlClient.SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint "FK_UserProfile_ProfilePropertyDefinition". The conflict occurred in database "C:\LUKE\VISUAL STUDIO 2005\WEBSITES\DNN\APP_DATA\DATABASE.MDF", table "dbo.ProfilePropertyDefinition", column 'PropertyDefinitionID'. The statement has been terminated. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteNonQuery(SqlConnection connection, CommandType commandType, String commandText, SqlParameter[] commandParameters) at Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteNonQuery(String connectionString, CommandType commandType, String commandText, SqlParameter[] commandParameters) at Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteNonQuery(String connectionString, String spName, Object[] parameterValues) at DotNetNuke.Security.Membership.Data.SqlDataProvider.UpdateProfileProperty(Int32 ProfileId, Int32 UserId, Int32 PropertyDefinitionID, String PropertyValue, Int32 Visibility, DateTime LastUpdatedDate) at DotNetNuke.Security.Profile.DNNProfileProvider.UpdateUserProfile(UserInfo user) at BTS.BTSServer.UpdateUser(String ContactID, DataRow Row) in C:\Luke\Visual Studio 2005\WebSites\DNN\App_Code\clsBTSServer.vb:line 189 at BTS.BTSServer.UploadContacts(String Criteria) in C:\Luke\Visual Studio 2005\WebSites\DNN\App_Code\clsBTSServer.vb:line 244 at Modules.BTSUserImport.View.btnImport_Click(Object sender, EventArgs e) in C:\Luke\Visual Studio 2005\WebSites\DNN\DesktopModules\BTSUserImport\View.ascx.vb:line 69 --- End of inner exception stack trace ---
Any help or advice appreciated.
Luke