CRM 4.0 upgrade problem with custom statistics
During an upgrade from CRM 3.0 to CRM 4.0 we have seen that the upgrade fails. The following 2 errors have been reported in the setupsrv4.log file.
1. First error:
System.Data.SqlClient.SqlException: The statistics 'xxxxxxxxx' is dependent on column 'xxxxxxxxxx'.
(xxxxxxxx = placeholder for the statistics or table names)
2. Followed by:
System.Data.SqlClient.SqlException: There is already an object named 'AttributeTypes' in the database.
This problem is caused by custom made SQL statistics on the CRM 3.0 tables in the Organization_MSCRM database.
Since the setup application is not aware of those SQL statistics it fails to ALTER the table columns that are referenced in the statistics.
You can work around this problem by dropping all user made SQL statistics from the tables in the Organization_MSCRM database e.g. by executing the following T-SQL script in the SQL Server Management Studio against the Organization_MSCRM database before you start the upgrade:
declare @sql nvarchar(2048)
declare @TableName nvarchar(512)
declare @StatName nvarchar(512)
declare StatisticsCursor cursor
for
select o.Name, s.Name
from sys.stats s
join sys.objects o on (o.object_id = s.object_id)
where s.user_created = 1
open StatisticsCursor
fetch next from StatisticsCursor
into @TableName, @StatName
print 'Dropping Custom Statistics'
print '=========================='
while @@fetch_status = 0
begin
set @sql = 'drop statistics ' + @TableName + '.' + @StatName
print 'Dropping: ' + @TableName + '.' + @StatName
print @sql
exec sp_executesql @sql
fetch next from StatisticsCursor into @TableName, @StatName
end
close StatisticsCursor
deallocate StatisticsCursor
Greetings,
Alex Leu