AXForum  
Вернуться   AXForum > Microsoft Dynamics CRM > Dynamics CRM: Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 05.10.2012, 23:12   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
crminthefield: Cleaning up CRM Sync Entry tables
Источник: http://blogs.msdn.com/b/crminthefiel...ry-tables.aspx
==============

If you’re CRM system has been up and running for a long period of time and your users have the CRM Outlook client installed (or have had it installed in the past) you’ll find many tables starting in SyncEntry_ as well as SubscriptionStatistics_ in your database. These tables are used to track items that are synchronized down to users client machines, however, when users get new client machines or leave the company the tables are left behind indefinitely.  This script has become a cleanup step we run with our customers prior to upgrading or periodically to prune out old sync data.  

Important NOTES about this script:

  • Always make a backup before running this script against your DB. 
  • Running scripts that modify your database are not supported, thus we’ve gone to great lengths to test this and make sure that all entries are cleaned out.  As of today this script can successfully run on:
    • CRM 4.0 UR7 and greater
    • CRM 2011 RTM through CRM 2011 Update Rollup 8
  • Do not modify any parameters or joins in this script or you could risk data damage
  • The script currently deletes all sync data older than 90 days
  • If a users sync entry data were to be deleted, the next time the user attempts to sync their client, the data would be rebuilt automatically
  • To test the script you can edit the “SET @execute = 1” and set it to a “0”, this will allow the script to run in a read-only mode and print out the SQL statements it would run to delete the tables.
Declare @SyncEnt varchar(60), @syncId uniqueidentifier, @SQL nvarchar(MAX), @execute bit--To run the deletions set this to 1, if it is 0 it will only print the statementsSET @execute = 1 DECLARE CRMSync_cursor CURSOR FORSELECT Replace(SyncEntryTableName,'SyncEntry_','') as SyncEntryGUID, SubscriptionId from subscription where LastSyncStartedOn < GetDate()-90 or LastSyncStartedOn is NULLOPEN CRMSync_cursorFETCH NEXT FROM CRMSync_cursor INTO @SyncEnt, @syncIdWHILE @@Fetch_Status = 0BEGIN IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID('subscriptionStatistics_'+@SyncEnt) AND type in (N'U')) BEGIN SET @SQL = 'DROP TABLE SubscriptionStatistics_' +(@SyncEnt) IF @execute=1 EXEC sp_executesql @SQL IF @execute=0 PRINT @SQL IF @execute=1 PRINT 'Dropped table: SubscriptionStatistics_'+(@SyncEnt)+ ' with error: ' + CAST(@@ERROR as varchar(255)) END ELSE IF @execute=1 PRINT 'SubscriptionStatistics table does not exist for subscriptionID: ' + CAST(@syncId as varchar(50)) IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID('SyncEntry_'+@SyncEnt) AND type in (N'U')) BEGIN SET @SQL = 'DROP TABLE SyncEntry_' +(@SyncEnt) IF @execute=1 EXEC sp_executesql @SQL IF @execute=0 PRINT @SQL IF @execute=1 PRINT 'Dropped table: SyncEntry_'+(@SyncEnt) + ' with error: ' + CAST(@@ERROR as varchar(255)) END ELSE IF @execute=1 PRINT 'SyncEntry table does not exist for subscriptionID: ' + CAST(@syncId as varchar(50)) SET @SQL = 'delete from SubscriptionManuallyTrackedObject where subscriptionId = ''' + CAST(@syncId as varchar(50)) + ''';' + 'delete from subscriptionclients where subscriptionId = ''' + CAST(@syncId as varchar(50)) + ''';' + 'delete from Subscriptionsyncinfo where subscriptionId = ''' + CAST(@syncId as varchar(50)) + ''';' + 'delete from subscription where subscriptionId = ''' + CAST(@syncId as varchar(50)) + '''' IF @execute=1 EXEC sp_executesql @SQL IF @execute=0 PRINT @SQL IF @execute=1 PRINT 'Dropped subscription table data for subscriptionId: ' + CAST(@syncId as varchar(50)) + ' with error data: ' + CAST(@@ERROR as varchar(255)) FETCH NEXT FROM CRMSync_cursor INTO @SyncEnt, @syncIdENDCLOSE CRMSync_cursorDEALLOCATE CRMSync_cursor
When the script runs you’ll be left with output such as the following showing you what was deleted and if there were any errors:

Dropped table: SubscriptionStatistics_6e64fbf450a1de11932b00155d88bd02 with error: 0Dropped table: SyncEntry_6e64fbf450a1de11932b00155d88bd02 with error: 0(0 row(s) affected)(0 row(s) affected)(766 row(s) affected)(1 row(s) affected)Dropped subscription table data for subscriptionId: 6E64FBF4-50A1-DE11-932B-00155D88BD02 with error data: 0



Источник: http://blogs.msdn.com/b/crminthefiel...ry-tables.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 8 Blog bot Dynamics CRM: Blogs 1 30.04.2016 10:26
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 10 Blog bot Dynamics CRM: Blogs 0 17.08.2012 03:27
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 7 Blog bot Dynamics CRM: Blogs 0 27.03.2012 02:11
Microsoft Dynamics CRM Team Blog: Update Rollup 5 for Microsoft Dynamics CRM 2011 Blog bot Dynamics CRM: Blogs 2 27.10.2011 17:11
crminthefield: Podcast and Overview: Microsoft Dynamics CRM 2011 Update Rollup 4 Blog bot Dynamics CRM: Blogs 0 24.09.2011 01:16

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 09:16.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.