Error: Sitemanagement is Currently Unavailable when attempting to delete portal

Error: Sitemanagement is currently unavailable

Please note: This article is meant for advanced users of Microsoft SQL Server users. If you don't feel comfortable doing this you may contact our support department for any help.
When you attempt to delete a portal under Site Management you get the below error:
Error: Sitemanagement is currently unavailable. DotNetNuke.Services.Exceptions.ModuleLoadException: The DELETE statement conflicted with the REFERENCE constraint "FK_TabPermission_Roles". The conflict occurred in database "somedatabase", table "dbo.TabPermission", column 'RoleID'.
The statement has been terminated. ---> System.Data.SqlClient.SqlException: The DELETE statement conflicted with the REFERENCE constraint "FK_TabPermission_Roles". The conflict occurred in database "somedatabase", table "dbo.TabPermission", column 'RoleID'.
The statement has been terminated.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   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, Int32 timeout, Task& task, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at PetaPoco.Database.Execute(String sql, Object[] args)
   at DotNetNuke.Data.PetaPoco.PetaPocoHelper.ExecuteNonQuery(String connectionString, CommandType type, Int32 timeout, String sql, Object[] args)
   at DotNetNuke.Data.SqlDataProvider.ExecuteNonQuery(String procedureName, Object[] commandParameters)
   at DotNetNuke.Data.DataProvider.DeletePortalInfo(Int32 PortalId)
   at DotNetNuke.Entities.Portals.PortalController.DeletePortalInfo(Int32 portalId)
   at DotNetNuke.Entities.Portals.PortalController.DeletePortal(PortalInfo portal, String serverPath)
   at DotNetNuke.Modules.Admin.Portals.Portals.OnGridDeleteCommand(Object source, GridCommandEventArgs e)
   --- End of inner exception stack trace ---
The physical files on the server under C:\inetpub\vhosts\<domain>\portals\<portalID> are deleted but the data in the database is unable to delete due a foreign key constraint not able to delete its references properly. The main issue is that on the DELETE action for the foreign key is not set to cascade, setting it to cascade will help resolve this issue.
To correct this issue you can attempt the following:
Prior to doing this it is highly recommended that you backup your database.
Specifically with this error message recieved it is referencing the dbo.TabPermission and the FK_TabPermission_Roles foreign key constraint it may be others if there are other foreign keys having dependency issues
  1. Log in to your database via SQL management studio
  2. Select your database
  3. On the database you want to make changes to you need to run the below SQL query this query will let you identify wether:
    sp_help [table_name]
    * The table name is without the dbo.
  4. Find the table that the error message you are getting. Right-click the table name and select Design
  5. Once you are in the design mode select the relationships button from (the one circled red):
  6. On the Foreign Key Relationships window you will see the list of the foreign keys. The one for this example is for the FK_TabPermission_Roles foreign key. Select FK_TabPermission_Roles relationship
  7. In the section named INSERT And Update Specific change the Delete Rule to Cascade
  8. Doing this will not save any information to the database. You will need to select the Generate Change Script button (the one circled red):
  9. Save the script to your desktop and leave the name the same
  10. You will then need to run the script from within SQL Management Studio. While still in the database you are using. Select the New Query button and open the SQL file in notepad or any text editor and copy and paste the contents into the query window

Add Feedback