Error: Error,"The "RunServiceRevisions" task failed unexpectedly."

Error when upgrading to patch 107 of 2.9 

"Error","The "RunServiceRevisions" task failed unexpectedly.
Blackbaud.AppFx.Platform.BuildTasks.RunServiceRevisionsHelpers.RevisionExecutionException: An error occurred while executing a service revision.
Revision text:
set nocount on;

declare @QUERYDEFINITIONXML xml;
declare @CHANGEAGENTID uniqueidentifier;

exec dbo.[USP_CHANGEAGENT_GETORCREATECHANGEAGENT] @CHANGEAGENTID output;

if object_id('tempdb..#SELECTIONS') is not null
  drop table #SELECTIONS;

if object_id('tempdb..#SELECTIONSTOIGNORE') is not null
  drop table #SELECTIONSTOIGNORE;

create table #SELECTIONS (
  [ID] uniqueidentifier not null primary key
);

create table #SELECTIONSTOIGNORE (
  [ID] uniqueidentifier not null primary key
);

--Find all selections we are trying to hide from ad-hoc query...
insert into #SELECTIONS ([ID])
  select [ID]
  from dbo.[IDSETREGISTER]
  where [ISSYSTEM] = 0
  and ([USEINQUERYDESIGNER] = 1 or [ACTIVE] = 1)
  and [ID] in (
    select [MKTSEGMENTATIONACTIVATE].[NORMALGIFTIDSETREGISTERID]
    from dbo.[MKTSEGMENTATION]
    inner join dbo.[MKTSEGMENTATIONACTIVATE] on [MKTSEGMENTATIONACTIVATE].[SEGMENTATIONID] = [MKTSEGMENTATION].[ID]
    where [MKTSEGMENTATION].[ACTIVE] = 1
    and [MKTSEGMENTATIONACTIVATE].[NORMALGIFTIDSETREGISTERID] is not null
    union all
    select [MKTSEGMENTATIONACTIVATE].[UNRESOLVEDGIFTIDSETREGISTERID]
    from dbo.[MKTSEGMENTATION]
    inner join dbo.[MKTSEGMENTATIONACTIVATE] on [MKTSEGMENTATIONACTIVATE].[SEGMENTATIONID] = [MKTSEGMENTATION].[ID]
    where [MKTSEGMENTATION].[ACTIVE] = 1
    and [MKTSEGMENTATIONACTIVATE].[UNRESOLVEDGIFTIDSETREGISTERID] is not null
    union all
    select [IDSETREGISTERID]
    from dbo.[MKTSEGMENT]
    where [IDSETREGISTERID] is not null
  );


declare AQCURSOR cursor local fast_forward for
  with xmlnamespaces ('Blackbaud.AppFx.WebService.API.1' as ns)
  select
    [QUERYDEFINITIONXML]
  from dbo.[ADHOCQUERY]
  where exists(
    select *
    from [QUERYDEFINITIONXML].nodes('ns:AdHocQuery/*/ns:f/ns:IDSetFieldInfo') as T(c)
    where T.c.value('(ns:ID)[1]', 'uniqueidentifier') in (select [ID] from #SELECTIONS)
  );

open AQCURSOR;
fetch next from AQCURSOR into @QUERYDEFINITIONXML;

while (@@fetch_status = 0)
begin
  --Save all the "Normal" and "Unresolved" selections that we need to ignore (ie - these need to stay visible in the query designer)
  with xmlnamespaces ('Blackbaud.AppFx.WebService.API.1' as ns)
  insert into #SELECTIONSTOIGNORE ([ID])
    select distinct T.c.value('(ns:ID)[1]', 'uniqueidentifier')
    from @QUERYDEFINITIONXML.nodes('ns:AdHocQuery/*/ns:f/ns:IDSetFieldInfo') as T(c)
    where T.c.value('(ns:ID)[1]', 'uniqueidentifier') in (select [ID] from #SELECTIONS);

  fetch next from AQCURSOR into @QUERYDEFINITIONXML;
end

close AQCURSOR;
deallocate AQCURSOR;


--Hide all "Normal", "Unresolved", and "Segment" selections from the query designer, except for any selection currently in use by an ad-hoc query...
update dbo.[IDSETREGISTER] set
  [USEINQUERYDESIGNER] = 0,
  [ACTIVE] = 0,
  [CHANGEDBYID] = @CHANGEAGENTID,
  [DATECHANGED] = getdate()
where [ID] in (select [ID] from #SELECTIONS)
and [ID] not in (select [ID] from #SELECTIONSTOIGNORE);

drop table #SELECTIONS;
drop table #SELECTIONSTOIGNORE;
             ---> System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK__#SELECTI__3214EC271F70280E'. Cannot insert duplicate key in object 'dbo.#SELECTIONSTOIGNORE'. The duplicate key value is (fb08f5c9-cfad-4352-9471-59acb6aa3c38).
The statement has been terminated.
   at System.Data.SqlClient.SqlConnection.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.RunExecuteNonQueryTds(String methodName, Boolean async)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at Blackbaud.AppFx.Platform.BuildTasks.RunServiceRevisionsHelpers.RevisionRunner.RunSQLRevision(String sql, Boolean useATransaction)
   at Blackbaud.AppFx.Platform.BuildTasks.RunServiceRevisionsHelpers.RevisionRunner.RunRevs(DBRevisions revs, Int32 startAtRevisionID, Boolean onlyLoadNonDesignerSpecs)
   --- End of inner exception stack trace ---
   at Blackbaud.AppFx.Platform.BuildTasks.RunServiceRevisionsHelpers.RevisionRunner.RunRevs(DBRevisions revs, Int32 startAtRevisionID, Boolean onlyLoadNonDesignerSpecs)
   at Blackbaud.AppFx.Platform.BuildTasks.RunServiceRevisionsHelpers.RevisionRunner.RunLatestRevisions()
   at Blackbaud.AppFx.Platform.BuildTasks.RunServiceRevisions.Execute()
   at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult)"
"2012-09-14 08:45:59","Information","Target "RunServiceRevisions" failed."

Download and install the latest patch, which contains all fixes from previous patches. If you are running an older version, download and install the latest version and then the patch. 

Environment

 6.35.1001, patch 109

Was this article helpful?