22 October 2007

Folder with GUID does not exist

Problem/Symptoms
An error similar to the following continues to be logged into the Altiris Notification Server a.log:
Process: aexsvc.exe (1756)
Thread ID: 652
Module: AltirisNativeHelper.dll
Source: Altiris.NS.ItemManagement.Item.MoveToFolder
Description: Folder with guid 5e2a1ce8-0af7-40f8-9b81-1539c61f829e does not exist.


Cause
These messages often occur when the user has done the following:
1. Enabled a Software Delivery Task for a collection.
2. The computers in the collection execute the Software Delivery Task.
3. The administrator deletes the Software Delivery Task.
What the administrator forgot to do was to Disable the Software Delivery Task and then allow all of the computers in the environment to update their polices so that each agent knows not to request this specific package.

Resolution
The long term solution to this problem is to ensure the following steps are followed prior to removing Software Delivery tasks:
1. Enabled a Software Delivery Task for a collection.
2. The computers in the collection execute the Software Delivery Task.
3. When the administartor decides the Task Should no longer be available, Disable the Task.
4. Wait at least 1 week to ensure most (if not all) of the machines in the environment have received updated configuration settings to stop requesting this package.
5. Delete the Software Delivery Task.
The short-term solution is to run the following SQL query by doing the following:
1. Each instance of the error message logged in the a.log will contain a unique GUID. Make a note of this GUID so you can use it later in this process.
2. Open Microsoft SQL Query Analzyer.
3. Create a New Query using the following SQL:

use Altiris
-- Temporary table to hold Table and Column names that are related to GUID
create table #TablesWithGuid
(
Tablename varchar(255),
ColName varchar(255),
Rows int
)

-- Declare the variables
declare @TableName varchar(255),
@ColName varchar(255),
@GUID varchar(40),
@xtype int,
@strSql nvarchar(4000),
@SqlResult int

-- GUID that is being searched for.
set @GUID = rtrim(ltrim('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' ))

-- Drop outside characters if longer than 36. (Eg. { and } characters)
if len(@GUID) = 38 and charindex('{',@GUID,1) = 1 and charindex('}',@GUID,1) = 38
begin
set @GUID = substring(@GUID, 2, 36)
end
else if len(@GUID) <> 36
begin
select 'Invalid Guid Specified' as [Error]
return
end

-- Tables with a 'Guid'in the column name or having a Uniqueidentifier column. Full column name as well.
declare GuidTableCol cursor for
select distinct
cast(so.name as varchar(255)) as 'Table Name',
cast(co.name as varchar(255)) as 'Guid Column',
co.xtype
from sysobjects so
inner join (
select name, id, xtype
from syscolumns
where name like '%Guid%'
or xtype = 36
) co on co.id = so.id
where so.xtype = 'U' --Only User Tables

open GuidTableCol
fetch next from GuidTableCol into @TableName, @ColName, @xtype

while @@FETCH_STATUS = 0
begin
--Find which tables and columns have a matching Guid to the one we are searching for.
set @SqlResult = 0

--Set guid string to have brackets if the column is a varchar
if @xtype = 167
begin
set @GUID = '{' + @GUID + '}'
end

-- Build the SQL Query string
set @strSql = '
select @Result = count(CAST([' + @ColName + '] as varchar(40)))
from [' + @TableName + ']
where cast([' + @ColName + '] as varchar(40)) = ''' + @GUID + ''''

-- Execute the SQL Query string
execute sp_executesql @strSql, N'@Result int out', @SqlResult out

--If the result count is > 0 then add table, column, and count to #TablesWithGuid
if @SqlResult > 0
begin
insert into #TablesWithGuid values (@TableName, @ColName, @SqlResult)
end

--Reset guid string
if @xtype = 167
begin
set @GUID = substring(@GUID, 2, 36)
end
fetch next from GuidTableCol into @TableName, @ColName, @xtype
end

-- Close cursor and deallocate
close GuidTableCol
deallocate GuidTableCol

-- Display results
--select * from #TablesWithGuid

-- Delete script
select ' declare @GUID uniqueidentifier'
union
select ' set @GUID = ' + Char(39) + cast(@GUID as nvarchar(36)) + Char(39)
union
select ''
union
select 'delete from ' + [Tablename] + ' where ' + [ColName] + ' like ' + '@GUID'
FROM #TablesWithGuid

-- Drop temp table
drop table #TablesWithGuid
4. Replace the Red Xs in the query above with the GUID from the error message.
5. Run the query in SQL Query Analyzer by pressing F5.
6. If necessary, repeat this procedure for each instance of the error in the log files, remembering to substitute the GUID each time.

No comments: