Delete User, Wiki Pages Reference Constraint - CS 2008.5 SP1

 Here's a quick hot fix for everyone out there frustrated with not being able to delete users from their community and are receiving this error, or something similar(Please remember to always backup your database):

The DELETE statement conflicted with the REFERENCE constraint "FK_cs_Wiki_Pages_cs_Users". The conflict occurred in database "clientintellectcore", table "dbo.cs_Wiki_Pages", column 'UserId'.
The statement has been terminated.

The problem here is a little something the developers left out of the cs_User_Delete stored procedure that reassignes Wiki pages to the anonymous or specified user. So in this case, the user is attempted to be deleted, and SQL finds that the cs_Wiki_Pages table still contains a reference to a user no longer there, and thus throws a reference constraint. To eliminate the problem is pretty simple, just adding about four lines to a stored procedure. First open up your SQL Server Management Studio and navigate to your CS database. Then inside Programmability->Stored Procedures, locate the cs_User_Delete Stored Procedure(Sproc). Right click that sproc and select "Modify". Scroll down until you see the below line:

EXECUTE cs_Posts_ReindexByUser @UserID

IF (@@ERROR <> 0) GOTO 

-- reassign content

Then just below that add these specific four lines:

UPDATE cs_Wiki_Pages

SET UserID = @ReassignUserID

WHERE UserID = @UserID

IF (@@ERROR <> 0) GOTO Failure

 

Now hit F5 or Execute and modify the Sproc. Your site should now be able to delete users!

#1 ricky on 5.04.2009 at 8:20 PM

thank you man!

#2 Sulumits Retsambew on 6.22.2009 at 7:41 AM

hello, this is my first time i visit here. I found so many interesting in your blog especially on how to determine the topic. keep up the good work.

#3 April Orlofsky on 10.30.2009 at 9:44 AM

Just an addition.... I was having this error and stumbled on your update. Thanks! I added a few more statements that should cover ALL Wiki records:

-- The following tables have UserID set up as a FK, but not as PK.

-- Reassignments are viable

UPDATE cs_Wiki_Pages

SET UserID = @ReassignUserID

WHERE UserID = @UserID

IF (@@ERROR <> 0) GOTO Failure

UPDATE cs_Wiki_PageComments

SET UserID = @ReassignUserID

WHERE UserID = @UserID

IF (@@ERROR <> 0) GOTO Failure

UPDATE cs_Wiki_PageRevisions

SET UserID = @ReassignUserID

WHERE UserID = @UserID

IF (@@ERROR <> 0) GOTO Failure

-- The following tables have UserID set up as PK and FK.

-- Reassignments are NOT viable (target user might already have record stored, causing duplicate key errors on reassignment)

-- Delete is only viable option

DELETE

FROM cs_Wiki_PageRatings

WHERE UserID = @UserID

IF (@@ERROR <> 0) GOTO Failure

DELETE

FROM cs_Wiki_PageCommentRatings

WHERE UserID = @UserID

IF (@@ERROR <> 0) GOTO Failure

/*

The following tables have UserID set up as PK but not FK. No action required

cs_Wiki_PageFollowers

*/

Leave a Comment


Pornstar Galleries Videos Porno Horny Babes and wet pussys Boobs Hot free live shows Free webcam video Gallery Archives Sex Movies Futanari Anime Hot Sex Cam Sex 24 Hours a day sexy webcam girls Live naked web Lesbian Live Sex Brunette babes Online dating services Free XXX