0% found this document useful (0 votes)
80 views

OP2 OLWhitepaper

Uploaded by

janisve
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views

OP2 OLWhitepaper

Uploaded by

janisve
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

Dynamics 365

On-Premises to Online Migration


Process

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 1


Copyright

This document is provided "as-is". Information and views expressed in this document, including URL and other
Internet Web site references, may change without notice.

Some examples depicted herein are provided for illustration only and are fictitious. No real association or
connection is intended or should be inferred.
This document does not provide you with any legal rights to any intellectual property in any Microsoft product.
You may copy and use this document for your internal, reference purposes. You may modify this document for
your internal reference purposes.
The videos and eBooks may be in English only. Also, if you click the links, you may be redirected to a U.S. website
whose content is in English.
© 2024 Microsoft. All rights reserved.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 2


CONTENTS
OVERVIEW 5
1.1. SCOPE AND ELIGIBILITY 5
1.2. MIGRATION REQUEST NOMINATION 5
1.3. DISCLAIMER AND GUIDANCE 5
HIGH LEVEL PROCESS OVERVIEW 5
2.1. LIFECYLE SERVICES (LCS) AND ACCESS TO THE TOOL 6
2.2. TYPES OF MIGRATION PROJECTS 6
Dry run 6
Production mock 6
Production migration 6
2.3. MIGRATION PROJECT PHASES 7
MIGRATION TOOL STEP-BY-STEP 7
3.1. PLANNING CONSIDERATIONS BEFORE STARTING MIGRATION. 7
3.2. LCS SIGN-UP AND OP2OL CAPABILITY ACTIVATION 8
3.3. CREATING NEW PROJECT 8
3.4. INVITE OTHER USERS/MIGRATION FACTORY TO LCS PROJECT 9
3.5. PHASE 1 - CUSTOMER INFORMATION GATHERING 9
Step 1.1 - Pre-Requisites 9
Step 1.2 – Enter Microsoft Dynamics CRM organization details 10
SQL to get the Database size 11
Step 1.3 - Access Migration Service storage 12
Step 1.4 - Upload CRM On-premise SQL database backup file 12
Take a SQL Database backup 12
Upload CRM SQL Database backup 12
Select Backup File 14
3.6. PHASE 2 - PROVISION & UPGRADE CRM ON-PREMISE ORGANIZATION 15
Task 2.4 - Map and validate AD Users file 15
Task 2.5 - Upgrade Microsoft Dynamics CRM organization 18
3.7. PHASE 3 - PROVISION AND MIGRATION TO DYNAMICS 365 19
Task 3.1 - Migrate Microsoft Dynamics CRM organization to Dynamics 365 19
Task 3.2 - User Mapping 21
Task 3.3 - Complete Online Migration 21
VALIDATING SOLUTIONS AND CUSTOMIZATIONS 22
POST MIGRATION ACTIVITIES 23
ADDITIONAL CONSIDERATIONS AND RECOMMENDATIONS 23
6.1. PLANNING AND MANAGING MIGRATION RUNS 23
Multiple runs 23
Multiple Environments and Multiple Runs 23
Runbook 23
6.2. TRANSITION TO UNIFIED INTERFACE 24
6.3. TRANSITION TO POWER AUTOMATE 24
6.4. TRANSITION FROM OUTLOOK CLIENT TO APP FOR OUTLOOK 24
6.5. ARCHIVING OR CLEANING UP DATA BEFORE MOVING TO ONLINE 24
6.6. SERVICE ACCOUNTS AND APPLICATION USERS MAPPING 24
6.7. NEW RELEASES DEPRECATIONS 24

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 3


6.8. DATA VALIDATION 25
6.9. MANUAL BACKUP 25
6.10. AUDITING 25
FAQ 25
7.1. WHERE DOES MY DATA RESIDE DURING STAGING? 25
7.2. WHO ACCESSES MY DATA AND HOW IS IT PROTECTED? 25
7.3. HOW LONG DO YOU RETAIN THE DB THAT IS UPLOADED? 25
APPENDIX A - REMOVING FULL TEXT CATALOG 26
APPENDIX B - FOR DATABASE FILE OVER 900 GB USE FOLLOWING STEPS TO SPLIT THE FILE. 28

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 4


Overview
The migration of an On-premises implementation to Online was never an easy task to achieve. The typical scenario
would include not only the move and transformation of the customizations/solutions and integrations but also
the time-consuming and challenging tasks of data migration.

Many customers expect that migrating to online would be an easy task facilitated by Microsoft where the
customer can provide their organization, which then becomes provisioned in Dynamics 365 Online. While
complete automation is not possible due to the complexity of the solution, the tool and process described in this
document provide a way to perform a migration from on-premises to online (OP2OL) with the least effort possible.

1.1. Scope and eligibility


The tool and migration process is available to all on-premises CRM customers and Microsoft Partners that utilize
supported versions of the application and related components.

Please pay attention to the supported versions and ensure they follow the supportability/compatibility
documentation. Minimum supported CRM on-premises version for this migration service is CRM 2015.

1.2. Migration request nomination


Microsoft Partners can nominate customers for OP2OL migration using nomination form here -
https://aka.ms/op2olnom. If the customer isn’t working with any partner then they should reach out to
Microsoft Migration Factory team for self-nomination.

1.3. Disclaimer and guidance


It is important to note that this migration tool is a no cost service offered by Microsoft. While we strive to meet
project timelines and ensure a smooth migration experience, we want to clarify that our company is not liable
for any expenses, penalties, or losses incurred by the customer due to delays in project timelines or missed go-
live dates. It is also the customer’s responsibility to validate the migrated instance. We recommend thorough
planning and consideration of potential setbacks to minimize any impact on your organization.

High level process overview


The migration process provides a guided way to move CRM on-premises to the cloud without the need to reimport
the data and thus reduce time and costs. The migration process and tool is supported by Migration Factory team
(also known as Factory Team).

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 5


2.1. Lifecyle Services (LCS) and access to the tool
The On-Premises to Online Migration tool is accessed through the Life Cycle Services Portal and provides a
template for migration methodology called “CRM On-premises to D365 Migration” which is used to create the
Project for migration. The tool is available to FastTrack, eligible Customers and Partners approved by Microsoft
FastTrack. Access to your regional LCS portal is activated after successful onboarding to the Program through the
nomination process. The onboarding process includes whitelisting customers’ tenant to access LCS.

2.2. Types of migration projects


Dry run
The objective of conducting dry runs is to ensure the successful completion of end-to-end migration. Although
these attempts are susceptible to errors, they serve to enhance learning, capture failures, prepare remediation
steps, mitigate issues, and ultimately achieve successful migration. Given the complexity of this significant
migration process and the potential challenges associated with migrating older versions, it is recommended to
conduct dry runs. The dry runs will help in identifying the technical issues and formulating mitigation steps for the
production migration.

In the event of encountering a failure not previously experienced, additional investigation and troubleshooting
are necessary, potentially extending the duration of the dry run. Response times are lenient, though the team is
committed to promptly resolving issues. The project team should be prepared for possible delays resulting from
these unforeseen circumstances.

A maximum of 2 successful dry runs is permitted. A dry run is deemed successful when the migration is not
abandoned. It's important to note that the primary objective of dry runs should not be the capture of end-to-end
timelines.

Production mock
Following the completion of dry runs, the Production Mock migration is scheduled close to the actual production
migration date, preferably a week before. This serves as a dress rehearsal for production migration, with the main
goal being to capture end-to-end timelines and complete migration with minimal failures. The experience gained
from this migration is typically repeated during production migration. If there are opportunities to reduce the
migration window, those steps will be deployed for the production migration.

All migration-blocking issues are addressed with the highest priority, similar to the approach to production
migration. Regular status updates are communicated via email.

Only a maximum of 1 production mock migration is allowed.

Production migration
Production migration must be scheduled within 1 to 2 weeks after the Production Mock is completed. During the
production migration, all blocking issues are handled with the highest priority, and regular email and/or Teams
chat updates are provided throughout the process. Factory team members are available for contact via Teams call
or chat at any time during this migration window. Failure to schedule the production migration within the
suggested timeframe after the Production Mock may result in potential delays in migration support from Factory
Team members.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 6


2.3. Migration project phases
Each migration project consists of three main phases below:

Phase 1 Phase 2 Phase 3


Customer information gathering Provision & upgrade of CRM on- Migrate to Dynamics 365 online
premises organization
Major pre-requisites are understood and Microsoft Dynamics CRM organization is Environment is validated and migrated
necessary details about CRM on- imported and upgraded. to customer’s online tenant.
premises organization DB is gathered to User mapping file is generated and User mapping is performed.
prepare migration environments. validated.
Customers are provided with a link to
upload the database once ready.

Migration tool step-by-step


This section has step-by-step instructions about how to use the Microsoft Dynamics CRM on-premises to Online
migration tool. The migration process runs in Dynamics LCS and can be accessed by signing in to your regional LCS
portal with your Microsoft 365 credentials (using User Principal Name). The tool consists of several automated
steps that don’t require customers’ input.

The below image shows migration process and highlights the steps with customer/partner responsibilities.

3.1. Planning considerations before starting migration.


1. Prepare for hiccups: Older Dynamics 365 versions and heavily customized deployments are more prone
to failures during initial dry runs. Capture these potential issues and build a migration knowledge base
for future reference. Plan for unforeseen migration issues that might cause delays. Allocate extra time to
address potential delays stemming from unforeseen migration issues.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 7


2. Microsoft support prioritization: On-call teams handle all production migration blockers with the
highest priority. If your dry run encounters problems requiring Microsoft intervention, resolving
production migration issues takes precedence. Expect longer wait-times for support during dry runs.
3. Dress rehearsal for production: Before the actual production migration, collaborate with the Migration
Factory team on a "production mock" run. This dress rehearsal helps identify and iron out any wrinkles
for a smooth production migration. Refer to Types of Migration for more details.

3.2. LCS sign-up and OP2OL capability activation


1. Navigate to LCS for your respective target region:

North America: https://lcs.dynamics.com


France: https://fr.lcs.dynamics.com
Europe: https://eu.lcs.dynamics.com
UAE: https://uae.lcs.dynamics.com
Switzerland: https://ch.lcs.dynamics.com
South Africa: https://sa.lcs.dynamics.com
GCC: https://gov.lcs.microsoftdynamics.us
GCC High: https://high.lcs.microsoftdynamics.us

2. Select Sign in.


It is important note that customers need to sign into LCS with the same user from the same tenant as
the sandbox org with CRM License which they plan to migrate to.

3. If you consent to the legal and privacy agreement, select Accept.

4. Once the above steps have been executed, please reach out to your Microsoft Migration Factory
contact with customers’ name and Tenant ID for activating your profile on LCS.
5. After your Microsoft contact confirms the activation, please make sure you Logout of the LCS portal and
Login again.

3.3. Creating new project


Consider creating the project at least a few days before the expected migration date. This buffer allows you as
well as the Microsoft factory team to complete all the mandatory tasks to prepare for smooth migration.

1. Select Lifecycle Services to open the LCS home page.


2. Select the plus sign (+) to start a new project.
3. Choose Migrate, create solutions, and learn under - What is this project for?
4. Provide a Name for the migration project.
5. Select Microsoft Dynamics CRM as the Product Name and Product Version.
6. Select CRM on-premises to D365 online migration (Kepler) as the methodology.
7. Select Create.
8. The project will be listed on the LCS home page. All the phases are pre-populated.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 8


3.4. Invite other users/migration factory to LCS project
The Microsoft team will work with you on certain steps of the LCS project. After the project is created, please
contact Migration Factory team ([email protected]) with the project number. Details about team
members to add will be shared with you.

To add either your colleagues or Migration Factory team members to the project:
1. Open the Project from LCS home.
2. Select the Project Users tile.

3. Select (+) to add the user to the project. Specify the Project role as Project owner, and then click Invite,
then please send the Project URL and Name to the Migration Factory team, notifying of the project
creation. NOTE: Please use UPN (e.g. alias@... instead of first.lastname@...)

3.5. Phase 1 - Customer information gathering


Step 1.1 - Pre-Requisites
Review this OP2OL whitepaper document and Tech Talk recording here. Please pay special attention to the pre-
requisites below.

Dynamics 365 Online


Please make sure you comply with all the pre-requisites below on your target tenant.
1. Dynamics 365 license and User Licenses are provisioned.
2. Ensure all users have Entra ID in Microsoft 365.

3. Appropriate user licenses are assigned.


4. A security group that will be used for the target instance is created and has members.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 9


5. Target sandbox environment with database and Dynamics 365 Apps provisioned.
6. Multi-Geo enabled (applicable if the tenant is in region different than the target organizations’ region).

On-Premises CRM Application


1. Convert custom SQL-based reports to FetchXML. If these reports are not converted, they will be
removed as part of the migration.
2. Plugins in sandboxed mode. Non-sandboxed plugin isolation mode is updated to Sandbox mode during
migration.

3. No plugins should be registered on the System User entity.

On-Premises SQL Database


1. Supported SQL and CRM version combination. Refer product documentation for supported SQL
versions

2. Database size is not more than 2TB. Let the factory team([email protected]) know if your On-
Prem database size is more than 2TB.
3. Databases over 900GB require additional work. Refer Appendix B for steps to split the data file.
4. The database collation needs to be aligned with default for the specified language (e.g.
‘Latin1_General_CI_AI’ for 1033). Supported Collations
5. SQL database backup set has only one LDF(log) file. Multiple datafiles are allowed.
6. The SQL DB recovery model should be set to simple before taking the backup.
7. Review the biggest tables in the database and reduce size. (Eg: AsyncOperationsbase table should be
cleaned, audit logs should be removed if not needed)

8. Full Text search should be set to “No” in Dynamics CRM On-prem and SQL full text indexes removed.

9. SQL TDE as well as any 3rd party encryption (using Symmetric Key) must disabled and DB/fields
decrypted before upload.
10. Remove Extra file groups
11. Run DBCC command to shrink the DB to get rid of empty space in the datafile.
12. Run command DBCC CHECKDB (‘DBName’) WITH EXTENDED_LOGICAL_CHECKS and provide output to
Microsoft team.

Step 1.2 – Enter Microsoft Dynamics CRM organization details


In this task you provide details about the Microsoft Dynamics CRM on-premises organization. This step must be
performed by Dynamics 365 Admin, Power Platform Admin or Global Admin user from the same tenant where
the environment will be hosted. The process records the TenantID from the user connected. If some other user
has performed this step and the TenantID is incorrect, please inform Microsoft to get this discrepancy addressed.
Also make sure the CRM and SQL versions are correct, else you may need to re-create the project.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 10


Company Name The name of the company you are migrating.

Organization name The unique name of the Microsoft Dynamics CRM on-premises organization.
It should not contain any spaces

Tenant id Tenant ID is pre-populated based on who is creating the LCS project.

Version (current) The Microsoft Dynamics CRM on-premises version of your database

SQL version The SQL Server version of Microsoft Dynamics CRM on-premises database.

CRM geo The region where D365 organization needs to be deployed. Please discuss
this option with Microsoft, to ensure you follow the best option according to
your scenario.

Sandbox Organization Name Please specify a target sandbox environment to which you are going to
migrate your on-premises database, e.g. for
mycompanytestmigration.crm4.dynamics.com you have to use
mycompanytestmigration. The environment will be overwritten. This
information should not be updated after entering Phase 2 of the project. If
any changes are needed, please contact Microsoft Factory Team.

CRM Region The name of the region where the environment will be migrated to.

Database size Enter the Database size here. The database size is not the same as the
backup file size. It is the size of (MDF + NDF) files (Giga bytes) of the on-
premises org database. Please use the given SQL to find the DB size.

Migration Type Dry Run, Production Mock or Production Run – this will help the Microsoft to
plan support accordingly.

Migration Date The date you’re targeting for the final step of migration (migrate to online)
to occur

Security Group Ignore this if you have already selected a security group at the environment
level.

SQL to get the Database size


Please run the following query on your DB and ensure that Step 1.2 Database Size field matches the output:
SELECT d.NAME
,ROUND(SUM(CAST(mf.size AS bigint)) * 8 / 1024, 0) Size_MBs
,CEILING((SUM(CAST(mf.size AS bigint)) * 8 / 1024) / 1024) AS Size_GBs
FROM sys.master_files mf
INNER JOIN sys.databases d ON d.database_id = mf.database_id
WHERE d.Name = ‘<Customer DB name>’
GROUP BY d.NAME

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 11


Remember to change the <Customer DB name> to your actual DB name. Please share the output with us for our
records.

IMPORTANT: Contact [email protected] after completing the above

Step 1.3 - Access Migration Service storage


Select the Resources for this Task, download and install the Microsoft Azure Storage Explorer.

Step 1.4 - Upload CRM On-premise SQL database backup file


Before taking the backup of the database, it is necessary gather the output of DBCC CHECKDB command.

1. Log into SQL Server Management Studio (SSMS).


2. Take note of the name of the database you are about to migrate.
3. Run DBCC CHECKDB(DBName). See screenshot below.

4. There should be 0 allocation errors and 0 consistency errors. If you notice any errors then, please fix
those before we attempt migration.
5. Once complete send the results in a Text file to Migration Factory contacts.

Take a SQL Database backup


The following steps need to be followed to get both, backup with checksum. Additionally for versions 9 onwards
it is necessary to retrieve the system users for the ADUsers mapping file. This process is described later in the
document.

To obtain backup with checksum you can run the following command in SSMS:

BACKUP DATABASE <MyOrg_mscrm>


TO DISK = ‘Z:\SQLServerBackups\MyOrg_mscrm.bak’
WITH CHECKSUM;
GO
If you prefer to take backup using GUI, you can enable the Perform checksum before writing to media option
under Options > Reliability in the SSMS. The complete process is described on in the following article.

Upload CRM SQL Database backup


Use the Microsoft Azure Storage Explorer tool to upload the Microsoft Dynamics CRM organization SQL backup
file into the container. Backup the Microsoft Dynamics CRM organization database as a single .bak file. It is
suggested that when taking the backup of the CRM organization database, the option to compress the backup.

IMPORTANT: Make sure you import the BAK file as a “block blob”, not “page blob”.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 12


If the Microsoft Dynamics CRM organization database name is contoso_MSCRM, name the backup file as
contoso_MSCRM.bak.

1. Open the LCS project and go to the Step 1.3. Access Migration Service storage.
2. Choose Create and Save Connection String under CRM Azure Storage Connection Manager.

3. Copy the Write key.


4. Open Azure Storage Explorer.
5. Select Connect icon (Plug) and choose Blob Container.

6. Select the Shared access signature URL (SAS) option.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 13


7. Click on Next.
8. Paste the Write Key you copied in step 2 into the URI and click Connect.
9. Locate folder lcs-<project number> and upload the DB_BackupFile_name.bak and ADUsers.csv files. It
is advised not to change Display name in Step 6 as its auto-populated with the LCS Project ID from the
SAS URL pasted in the second column.

Select Backup File


1. Select step 1.4 and open the slider.

2. If backup files are uploaded, you will be able to select the respective file from dropdown box.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 14


3. If the Blob Container is not created or no files are uploaded to the Container you will receive and error
message – Error Ocurred while retrieving all database backup file details or No database file was found
in the contained <LCS project number> respectively.

NOTE: Once connected, you will have 24 hours to upload the files. If the key expires, please contact Microsoft on
[email protected].

3.6. Phase 2 - Provision & Upgrade CRM On-premise Organization


In this phase the database is being prepared for upgrade process as well as the User Mapping file will be prepared.
Should the upgrade process fail, Microsoft team will make reasonable effort to address the problem. In certain
situations, it may be necessary to perform remediation steps before the database is backed up or uploaded. Please
work with Microsoft to gather more information and address the cause of the failure. After this step is completed,
the database is validated and migrated to the cloud.

Note: After kicking off Step 2.1 by factory team, Steps 2.3 and 2.5 will be performed automatically.

Task 2.4 - Map and validate AD Users file


It is necessary to map the existing Microsoft Dynamics CRM on-premises organization users to Microsoft 365 users
(UPN, i.e. alias@.... which is the email Id from the Microsoft admin center). When the Microsoft Dynamics CRM
organization is migrated, the users are mapped as specified in the mapping file.

TIP: If this is a test run and you only need a few users to work on the system after the migration is completed, just
map those. If this is a rehearsal for the final migration or the final migration itself, make sure you map all the users
you need to have mapped (these should exist and be licensed in the Microsoft 365 portal too).
Mapping B2B users (external domain) will require some specific actions, please consult Microsoft for those details.

Step 1 – Download Adusers.csv file


The ADUsers.csv file will be prepared for you as part of step 2.4. To access the file, use the Azure Storage Explorer
to download the file from Blob storage account to your local drive.

1. Open the LCS project and go to the “Step 1.3 Access Migration Service storage.
2. Choose Create and Save Connection String under CRM Azure Storage Connection Manager.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 15


3. Copy the Write key.
4. Open Azure Storage Explorer.
5. Select Connect icon (Plug) and choose Blob Container.

6. Select the Use a shared access signature (SAS) URI option.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 16


7. Click on Next.
8. Paste the Write Key you copied in step 2 into the URI and click Connect.
9. Locate folder lcs-<project number> and download the ADUsers.csv file.

Step 2 – Update and Save ADUsers.csv file


Open the file in Excel and update the column F (Target User) with the respective user principal name in
Microsoft 365.

If you use Notepad or similar editor, the structure of the file should be a comma separated values with double
quotes as qualifier, such as example below.

“SystemUserId”,”User Name”,”Full Name”,”Primary E-mail”,”IsLocalAdmin”,”TargetUser”


“91e5549c-0607-e711-80b8-001cc46abfb6”,”contoso\cadmin”,”First name Last
name”,”[email protected]”,”Yes”,[email protected]

Things to remember when updating the csv file:

✓ Make sure that there are no empty rows in the document, including first and last row.
✓ If there is no Primary E-mail for any user then please leave it blank.
✓ There should not be any duplicates UPN in the TargetUser column.

Save the file as ADUsers.csv (please note the name is case sensitive) and upload it to the Blob storage account as
described in step 3.4.7.

Validate ADUSers.csv
After the ADUsers file is uploaded you .must perform validation by selecting the Validate AD Users file in step 2.4

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 17


Task 2.5 - Upgrade Microsoft Dynamics CRM organization
This step is started by Microsoft team. You can track the progress by selecting the CRM Migration Tracker link.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 18


The upgrade tasks run in serial order. The time for completion of the upgrade depends on the organization size
and complexity.

Microsoft will monitor the progress. The upgrade process may fail due to issues on the source database, and
remediation steps may be necessary to proceed with migration. You may also be asked to raise a support ticket
and work with Microsoft Support Engineering team on the resolution steps.

3.7. Phase 3 - Provision and Migration to Dynamics 365

IMPORTANT: Before starting this phase, ensure environment you specified in Customer Information step exists
on Power Platform, if not, please create an environment WITH Database and Dynamics 365 Apps in Power
Platform Admin center and return to Step 1.2 to validate.

Task 3.1 - Migrate Microsoft Dynamics CRM organization to Dynamics 365


In this task the organization will migrate to the Cloud. Before the actual migration the tool runs a final series of
validation checks. Once all checks pass, the migration continues. If a validation check fails, steps need to be taken
to address the root cause of the failure. Time needed to finish this step depends, among other aspects, on the size
of the database. Previous dry runs help you to estimate the time necessary, allowing some additional buffer for
unexpected circumstances.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 19


1. Select Migrate to Dynamics 365 Online.

2. Accept the terms and conditions.


3. On the Ready to migrate page, verify the name of previously created Environment, if this does not
match please return to step 1.2 to correct it.

IMPORTANT: Please contact Microsoft ([email protected]) to initiate the Migrate Organization task.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 20


Task 3.2 - User Mapping
Step 3.2 allows you to perform additional user mapping after the organization is migrated to cloud. You can use
this step also in case some of the users failed to map in Phase 2. Please run this step only for the failed users or
any additional users that needs to be added.

Task 3.3 - Complete Online Migration


This task has to be done before the environment is handed over and used by the customer.

NOTE: Once this step is marked as complete, no further user mapping can be done through LCS. If there is
requirement for additional user mapping, Microsoft Support ticket needs to be raised.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 21


After all stages are complete; the organization is migrated to Cloud as a Sandbox organization. An administrator
or customizer can log in and validate if the organization is functional and subsequently convert it to full access
mode and a production organization.

NOTE: The Migration project and all the files in the storage account are deleted 7 days after the migration finishes.
If you need to keep the project and files available for longer period of time, please contact Microsoft.
If you need to delete the files earlier than 7 days after migration, you can access the Storage Account and delete
those manually.

Validating Solutions and Customizations


The purpose of this set of tasks is to validate and assess the readiness of the solutions and customizations before
moving online. This could be done directly in the on-premises systems, in the Azure hosted environments, or in
less impactful cases, just after the migration has been completed (presuming that some of the solution
components may not work at that point yet).
The PowerApps Solution Checker is the recommended tool for this task. It analyses customizations for the
Common Data Service and for Model-Driven apps. It will look for known problematic patterns that can negatively
impact the user experience. Additionally, PowerApps Solution Checker can be used to verify update readiness
issues. For example, it will detect a violation if you are using a deprecated API. Remember, deprecated doesn’t
mean removed - deprecated means that, at some point soon, it will be removed.

The PowerApps Solution Checker is available for most of our Dynamics 365/PowerApps customers, online and on-
premises. It’s supported for Dynamics CRM 2011 to the latest Common Data Service/Model-Driven apps solutions.
For online customers, you can run PowerApps Solution Checker within the PowerApps maker portal.
For on-premises you can leverage the API to run the assessments too. More information about the PowerShell
option can be found here: Automatically validate your solutions using the PowerApps checker PowerShell Module
| Microsoft Power Apps

You can use this process within your ALM standards to submit your solution files for analysis before you push the
changes to production.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 22


You can also automate the processing of solution analysis via PowerShell, as explained in this page:
https://github.com/jowells1/AutomatePowerAppsChecker

Post migration activities


After the migration is completed, additional actions will be performed in the backend which may impact the
immediate availability of the instance. Please be aware that you need to wait several minutes for the platform to
apply all the latest updates to the migrated organization, as well as install the Microsoft 1st party apps. You will be
informed about the completion of these tasks by the respective migration team members responsible for your
migration.

Once notified, you will be able to login and start importing your solutions. If you encounter errors importing your
solutions, related to dependencies from other Microsoft (or any other) apps, please verify if those are installed or
request assistance from your Microsoft contact or Microsoft Technical Support.

At this point, you can also re-configure your integrations to make those work with the newly migrated Dynamics
365 online environment.

Additional considerations and recommendations


6.1. Planning and Managing Migration Runs
Multiple runs
In a typical scenario you would be taking a full backup of the Production On-Premise system and migrate it – this
would leverage a full understanding of the efforts needed for transforming the solutions and provide you
approximate timings of the end-to-end process.

The approach in general terms is to move online as quickly as possible: not change anything in the original on-
Premises systems and rather just remove any blockers and take the time to work on the solution changes directly
in the Online environment.
You can have up to two successful dry runs (see also section 3.2) – these will require each time a new LCS project,
and they will help capturing failures and record the mitigation actions, preparing for the final go-live migration.
NOTE: Successful dry run is a migration that is completed. If there are errors/issues encountered as part of
migration that are mitigated, this is as well considered a successful migration as the mitigation steps are then
noted and will be performed in eth production migration should there be need to do so.

Multiple Environments and Multiple Runs


Another scenario would be to move the multiple on-Premises systems to online in different migration projects:
such as the development environment (DEV), test environments (UAT or SIT) and production. Make sure there is
final rehearsal (Production Mock) of end-to-end migration run for the production database before the real go live
to ensure that everything is ready and risk of failing at some point is left at the bare minimum.

NOTE: For any non-production database migration maximum 1 successful dry run is allowed.

Runbook
It is advisable to create a migration run book. Establish a logbook that aligns all migration-related tasks in a
sequential manner, recording detailed actions, owners, and expected start/finish times, will significantly
contribute to a successful migration. Make sure to include sufficient time buffers for any unforeseen situations.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 23


6.2. Transition to Unified Interface
Allocate the time saved during migration through this tool to enhance the quality of the solution and the
implementation of Unified Interface Apps. Make sure to capitalize on the transition to the new Unified Interface.
Review the necessary steps for a successful transition and ensure a seamless move with minimal impact on end
users. Additional information on the transition approach and process is provided in detail in the Unified Interface
Playbook. Unified Interface Playbook - Power Apps | Microsoft Docs

6.3. Transition to Power Automate


Consider migrating your CRM/Dynamics Workflows to Power Automate Flows as a means of scaling out. In
numerous scenarios, this transition can elevate your business processes to the next level, harnessing the potential
for integration with other systems, whether internal or external to the Power Platform. Create a cloud flow with
Dynamics 365 (online) - Power Automate | Microsoft Docs.

6.4. Transition from Outlook Client to App for Outlook


The Outlook COM-Add-in is no longer supported for Dynamics 365 in the Cloud. Instead, the integration has been
succeeded by the Dynamics 365 App for Outlook.

The Dynamics 365 App for Outlook enhances user experience across Outlook on desktop, web, or phone. Upon
installation, depending on the app version, users will observe a Dynamics 365 apps pane or window alongside
selected Outlook email messages. This feature is also visible when composing an email message or setting up a
meeting or appointment. Dynamics 365 App for Outlook Overview (Dynamics 365 apps) | Microsoft Docs

6.5. Archiving or cleaning up data before moving to Online


Very often customers complement this migration project with the archival or clearing of historical data, just before
the migration process.
Data records from known tables, such as AuditBase, AsyncOperationBase and others undergo cleansing before
the migration to the cloud. Cleanup of AsyncOperationBase is detailed in article: Performance is slow if the
AsyncOperationBase table becomes too large in Microsoft Dynamics CRM
Utilize Bulk Delete to eliminate unnecessary data prior to migrating to the cloud. Delete data in bulk (Developer
Guide for Dynamics 365 Customer Engagement (on-premises)) | Microsoft Docs
To transfer the data outside of Dataverse you can opt in for Azure Synapse Link - Power Apps | Microsoft Docs

6.6. Service Accounts and Application Users Mapping


When in On-Premises it is common to have specific accounts to run some integrations. A question comes on how
to handle these whilst doing user mapping: should they be a regular licensed user or an application user?
The general guidance is: if the account is for service-to-service communication, running integrations, this would
qualify as the “application user” scenario, so an appuser should be created and the re-configuration done: Create
users and assign security roles - Power Platform | Microsoft Docs
But if the so-called service account is such that it is used under some interactive scenarios as well or is performing
operations as a “regular user” (eg: owning a workflow), it should still be considered as a regular licensed user
when moving to online, with that, that specific account should also exist in the Microsoft 365 portal and have a
license assigned.

6.7. New releases Deprecations


As the transition to the cloud involves ongoing updates and enhancements, certain functionalities or
customizations from your source on-premises environment may be deprecated or removed in the cloud. To

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 24


ensure a successful migration and a smooth transition to normal operations, it is crucial to retain all functionality
and proactively address any issues that may arise from removed or deprecated features. Additionally, closely
monitoring the Release notes and deprecations on the Microsoft Documentation site is advisable. Eg.: Important
changes (deprecations) coming in Power Apps and Power Automate - Power Platform | Microsoft Docs

6.8. Data Validation


Post migration data validation is a critical phase for any migration process. It is advisable to create data validation
scripts that business users can utilize to confirm the successful completion of migration. Additionally, allocate
ample time for thorough data validation as part of post-migration procedures. Completing the data validation
within three (3) days is highly recommended, enabling prompt root cause analysis if any issues are identified.

6.9. Manual Backup


Following the migration to cloud, it is advised to manually create a backup and appropriately label it. This action
allows for the creation of a snapshot of the migrated database. In the event of any data discrepancies discovered
during validation, the database backup can be restored to verify whether any updates were made as part of post-
migration steps. In the case of sandbox environments, the backup is retained for seven (7) days, making it
advisable to complete data validation within three (3) days of migration completion.
https://docs.microsoft.com/en-us/power-platform/admin/backup-restore-environments#create-a-manual-
backup

6.10. Auditing
Audit logs assist administrators and other privileged users in reviewing the creation and update history of records.
During post-migration steps, there might be a requirement to update transactional or master data. It is advisable
to ensure that auditing is enabled before making any changes as part of post-migration steps.
https://docs.microsoft.com/en-us/power-platform/admin/manage-dataverse-auditing#configure-auditing-for-a-
dataverse-environment

FAQ
7.1. Where does my data reside during staging?
Location of the data during migration is determined by the region where the target sandbox environment resides.
This means, that if you create environment with URL myorg.crm4.dynamics.com, the Migration tool will be in
European datacenters. Additionally, ensure that you are utilizing the correct location for LCS tools; refer to section
3.2 for a list of available LCS endpoints.

7.2. Who accesses my data and how is it protected?


The OP2OL migration process is aligned with the Data Protection Addendum for Microsoft Services. This can be
obtained from Licensing Documents (microsoft.com).

7.3. How long do you retain the DB that is uploaded?


All artifacts associated with a successful migration will be deleted within 7 days following the migration. In the
case of unsuccessful migrations requiring additional investigation, data will be retained until the issue is resolved
or until we attempt migration again through the new LCS project.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 25


Appendix A - Removing Full Text Catalog
Please refer to the scripts below to disable and remove Full Text Search/Full Text Indexes as CRM Online
does not it.

Step 1:
-- Disable FullTextSearch
UPDATE OrganizationBase
SET IsFullTextSearchEnabled = 0 -- Drop FT indexes to address this issue:
/*
Cannot drop index 'cndx_PrimaryKey_ColumnMapping' because it enforces the full-text key for table or indexed
view 'ColumnMappingBase'. Could not drop constraint. See previous errors.
*/ DECLARE @output TABLE(tableName VARCHAR(1024)) DECLARE @T INT, @count INT, @dropTableName
VARCHAR(1024)
INSERT @output
SELECT OBJECT_NAME(object_id) AS TableName
FROM sys.fulltext_indexes
WHERE OBJECT_NAME(object_id) not in ('BusinessDataLocalizedLabelBase',
'DocumentIndex',
'MultiSelectAttributeOptionValuesBase')
SET @count =
(SELECT COUNT(*)
FROM @output)
SET @T = 1 WHILE @T <= @count BEGIN
SET @dropTableName =
(SELECT TOP 1 tableName
FROM @output) EXEC('DROP FULLTEXT INDEX ON ' + @dropTableName)
DELETE @output
WHERE tableName = @dropTableName
SET @T = @T + 1 END -- Drop SP to address an issue:
/*
Error in Action: Bin\Microsoft.Crm.ObjectModel.dll:InstallStoredProcedures on attempt 3.
System.Reflection.TargetInvocationException:
Exception has been thrown by the target of an invocation. ---> Microsoft.Crm.CrmException: Error
installing sp with name=EntityIdCollectionCreation
Cannot drop type 'dbo.EntityIdCollection' because it is being referenced by object
'p_GrantAccessBulkForCreate'.
There may be other objects that reference this type.
*/
DROP PROCEDURE [dbo].[p_GrantAccessBulkForCreate] GO -- Remove the FT indexes from the index tables
BEGIN TRANSACTION CleanUpMetadataSchema GO
DELETE
FROM [MetadataSchema].[IndexAttributes] WHERE [IndexId] IN
(SELECT [IndexId]
FROM [MetadataSchema].[EntityIndex]
WHERE IndexType = 9
AND [Name] not in ('BusinessDataLocalizedLabel_FullText',
'DocumentIndex_FullText')
February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 26
AND [State] <> 3 );

GO
DELETE
FROM [MetadataSchema].[EntityIndex]
WHERE IndexType = 9
AND [Name] not in ('BusinessDataLocalizedLabel_FullText',
'DocumentIndex_FullText')
AND [State] <> 3;
GO
COMMIT TRANSACTION CleanUpMetadataSchema

Step 2:
Deleting Full Text Catalog:

You can follow this documentation to learn how to find and delete full text catalogs:
https://docs.microsoft.com/en-us/sql/relational-databases/search/create-and-manage-full-text-
catalogs?view=sql-server-ver15

1. In SSMS, in Object Explorer, expand the server, expand Databases, and expand the database that
contains the full-text catalog you want to remove.
2. Expand Storage and expand Full Text Catalogs.
3. Right-click the full-text catalog that you want to remove, and then select Delete.
4. In the Delete Objects dialog box, click OK.

If the Catalog returns an error, run the following script:

DECLARE @catid int


SELECT @catid=fulltext_catalog_id
FROM sys.fulltext_catalogs
WHERE name='CRMFullTextCatalog' DECLARE c
CURSOR
FOR
SELECT sys.tables.name, sys.fulltext_indexes.unique_index_id
FROM sys.fulltext_indexes
INNER JOIN sys.tables ON sys.fulltext_indexes.object_id = sys.tables.object_id
WHERE sys.fulltext_indexes.fulltext_catalog_id=@catid OPEN c
DECLARE @TableName varchar(200), @UniqueID AS integer FETCH NEXT
FROM c INTO @TableName, @UniqueID WHILE @@fetch_status = 0 BEGIN DECLARE d
CURSOR
FOR
SELECT sys.indexes.name, sys.tables.object_id
FROM sys.tables
INNER JOIN sys.indexes ON sys.tables.object_id = sys.indexes.object_id
WHERE sys.tables.name=@TableName

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 27


AND sys.indexes.index_id = @UniqueID OPEN d DECLARE @KeyIndex varchar(200),
@object_id AS integer FETCH NEXT
FROM d INTO @KeyIndex, @object_id IF @@FETCH_STATUS <> 0
BEGIN PRINT 'Error with' + @TableName END
WHILE @@fetch_status = 0 BEGIN
BEGIN TRY PRINT 'DROP FULLTEXT INDEX ON [dbo].'+@TableName+';' PRINT 'GO' END TRY
BEGIN CATCH PRINT 'Error' + @KeyIndex END CATCH FETCH NEXT
FROM d INTO @KeyIndex, @object_id END CLOSE d DEALLOCATE d FETCH NEXT
FROM c INTO @TableName, @UniqueID END CLOSE c DEALLOCATE c

Step 3:
Run the output that is generated against your CRM OrganizationDB and it will drop all the indexes needed. And
the again try deleting the Full Text Catalog, it should succeed now.

Step 4:

To check for any Full text in database:


select OBJECT_NAME(object_id) as TableName from sys.fulltext_indexes where OBJECT_NAME(object_id) not in
('DocumentIndex', 'BusinessDataLocalizedLabelBase')

To check for any Full text in Entity Index table


You can rerun Step 1 queries to drop full text indexes again to verify all the fulltext indexes has been dropped as
they will return null outputs or 0 rows affected output.

Appendix B - For Database file over 900 GB use following steps to


split the file.
Note: Please test these steps on the non-production system before applying on Production database. Always
ensure to take backups before proceeding. The scripts provided are examples, and your experienced Database
Administrator (DBA) may suggest alternative approaches for splitting a database into multiple files.

DB name: mycrm_MSCRM
DB Size: 1TB
1. Add 4 additional files with initial size of 200 GB and an autogrowth of 512 MB will be added.
2. In the sample script, include two files to be added to the E:\ drive, and one file each to be added to the
G:\ and L:\ drives, respectively.
3. When performing on the Production database, schedule a rebuild index job to redistribute data across
all files, excluding the attachment table. Ensure this runs outside business hours.
4. Schedule a Log Backup job on the database at 5-minute intervals while the rebuild index is running to
prevent the Transaction Log file from filling up and causing disk space issues on the "log" drive. Note: Set
the recovery model to SIMPLE as per op2ol prerequisites.
5. Identify and drop any unused indexes on the production database.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 28


6. Once data is distributed evenly across all the files, schedule a shrink process.

All through these steps, consistently monitor the size of .MDF file, as you see the file size reducing, limit the max
file size to little over the file size [Example: if the size of .MDF file is 500 GB, set max size to 550 GB].

This is an iterative step, that must be run until the .MDF file size is ~ 250 GB.

Scripts to be used:
Note: Before running any of the scripts below, please consult with your DBA.

Script to add additional files:


/*
This script adds additional 4 files on the mycrm DB of 200 GB size each.
Following Directories are used in this example, please adjust as needed: E
:\SqlData\, L:\SqlData\, G:\SqlData\
Autogrowth is set to 512 MB
*/
USE [master]
go

ALTER DATABASE [mycrm_MSCRM] ADD FILE ( NAME = N'mycrm_MSCRM3', filename =


N'E:\SqlData\mycrm_MSCRM3.ndf', size = 209715200kb, filegrowth = 524288kb )
TO
filegroup [PRIMARY]
go

ALTER DATABASE [mycrm_MSCRM] ADD FILE ( NAME = N'mycrm_MSCRM4', filename =


N'E:\SqlData\mycrm_MSCRM4.ndf', size = 209715200kb, filegrowth = 524288kb )
TO
filegroup [PRIMARY]
go

ALTER DATABASE [mycrm_MSCRM] ADD FILE ( NAME = N'mycrm_MSCRM5', filename =


N'L:\SqlData\mycrm_MSCRM5.ndf', size = 209715200kb, filegrowth = 524288kb )
TO
filegroup [PRIMARY]
go

ALTER DATABASE [mycrm_MSCRM] ADD FILE ( NAME = N'mycrm_MSCRM6', filename =


N'G:\SqlData\mycrm_MSCRM6.ndf', size = 209715200kb, filegrowth = 524288kb )
TO
filegroup [PRIMARY]
go

In order to perform the data distribution by reindexing, the following Stored Procedure can be used:
create procedure [DBO].[P_DAMSREINDEXALL](@ALLINDEXTYPES int=1, --0:Clustered Index only, 1:
Clustered and Non Clustered indexes
@MAXRUNTIME int=NULL, --Maximum allowed running time (in seconds)
@FRAGREBUILDPCTHIGH int=30, --Min. Percentage of fragmentation above which indexes are
REBUILD unless @DefragType is set to 1.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 29


@FRAGREBUILDPCTLOW int=10, --Min. Percentage of fragmentation at which indexes are
REORGANIZED unless @DefragType is set to 2.
@MAXFRAGPCTTOREBUILD int=100, --Max. Percentage of fragmentation above which indexes won't be
rebuild or reorganized; useful for defrag within a defined range first, refer usage below
@DEFRAGTYPE int=0, --0: default (REORGANIZE fragmentation less than @FragRebuildPctHigh%;
REBUILD otherwise)
--1: ONLY perform ALTER INDEX ... REORGANIZE irrespective of fragmentation
--2: ONLY perform ALTER INDEX ... REBUILD irrespective of fragmentation
@MINPAGES int=1000, --do not touch tables less than 1000 pages
@VERBOSE int=0, --1: Print progress messages and detailed results including additional scan
for final fragmentation after reindex completes for reporting old/New ragmentation.
@ONLINE bit=1, --1: rebuild indexes ONLINE ONLY, if fails due to BLOB, perform REORGANIZE;
--0: rebuild indexes ONLINE first, if fails due to BLOB, perform OFFLINE rebuild
@MAXDOP int=16 --1: default
)
as
/********************************************************************************************
********************************************/
/*Usage

*/
/* 1. ONLY REORGANIZE for frag 10% - 40% : exec p_reindexAll
@FragRebuildPctLow=10, @MaxFragPctToRebuild=40, @DefragType=1 */
/* 2. ONLY REBUILD for frag 40% - 100% : exec p_reindexAll
@FragRebuildPctLow=40, @MaxFragPctToRebuild=100, @DefragType=2 */
/* 3. Defragment indexes (default beahvior): exec p_reindexAll --(REORGANIZE
fragmentation less than 30%; REBUILD otherwise) */
/********************************************************************************************
***/
/* RETURN CODES:
*/
/* 0 - Success
*/
/* 1 - Partial success - some indexes could not be rebuilt
*/
/* 2 - Partial success - Indexes were rebuilt, but some statistics were not updated
*/
/* 5 - Invalid input parameter(s)
*/
/********************************************************************************************
***/
/*
Returns
a) Always first recordset - one row with 4 integer columns:
ResultCode - see RETURN CODES
TotalIndexesToRebuild - total count of indexes detected
to be rebuild
RebuiltWithOnlineON - count of indexes rebuilt with
option ONLINE = ON
RebuiltWithOnlineOFF - count of indexes rebuilt with
option ONLINE = OFF (can't be rebuilt with ONLINE = ON)
TotalStatisticsToUpdate - total count of the indexes to update
statistics for
StatisticsUpdated - count of the number of
indexes updated
FragmentationScanDurationInSeconds - Duration to identify the fragmented indexes that
needs rebuild/reOrg
MiscStatsUpdateBeforeRebuildInSeconds - Duration for all UPDATE STATISTICS
dbo.Subscription* that are done before rebuild starts.
ReindexComments - Reports any comments to
be Loggged in Telemetry like # of Online ReBuild that failed due to BLOB.
b) Always second recordset - see @errors table
c) Only when @Verbose=1, then the second recordset with detailed info about all indexes
d) Only when @Verbose=1, then the third recordset with detailed info about all indexes to
update statistics on

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 30


*/
begin
set NOCOUNT on
declare @TOTALINDEXESTOREBUILDANDREORGANIZE int=0, @INDEXESREORGANIZED int=0,
@REBUILTWITHONLINEON int=0, @REBUILTWITHONLINEOFF int=0, @TOTALSTATISTICSTOUPDATE int=0,
@STATISTICSUPDATED int=0, @FRAGMENTATIONSCANDURATIONINSECONDS int=0,
@MISCSTATSUPDATEBEFOREREBUILDINSECONDS int=0 --Get start time for max run time tracking
declare @MAXTIME datetime=DATEADD(SS, ISNULL(@MAXRUNTIME, 0), GETUTCDATE()) --Account for
nulls in parameters, set to default values
set @ALLINDEXTYPES=ISNULL(@ALLINDEXTYPES, 1)
set @FRAGREBUILDPCTHIGH=ISNULL(@FRAGREBUILDPCTHIGH, 30)
set @FRAGREBUILDPCTLOW=ISNULL(@FRAGREBUILDPCTLOW, 10)
set @MAXFRAGPCTTOREBUILD=ISNULL(@MAXFRAGPCTTOREBUILD, 100)
set @DEFRAGTYPE=ISNULL(@DEFRAGTYPE, 0)
set @MINPAGES=ISNULL(@MINPAGES, 1000)
set @VERBOSE=ISNULL(@VERBOSE, 0)
set @ONLINE=ISNULL(@ONLINE, 1) --Validate parameters
if((@ALLINDEXTYPES not in (0,
1))OR(@MAXRUNTIME<=0)OR(@FRAGREBUILDPCTHIGH>100)OR(@FRAGREBUILDPCTHIGH<0)OR(@FRAGREBUILDPCTLO
W>100)OR(@FRAGREBUILDPCTLOW<0)OR(@MAXFRAGPCTTOREBUILD>100)OR(@MAXFRAGPCTTOREBUILD<0)OR(@DEFRA
GTYPE not in (0, 1, 2))OR(@MINPAGES<1)OR(@VERBOSE not in (0, 1))OR(@ONLINE not in (0,
1)))begin
PRINT 'Invalid Parameter value. Valid values are:'
PRINT 'AllIndexTypes in {0,1}'
PRINT 'MaxRunTime > 0,'
PRINT 'FragRebuildPctHigh in {NULL,0..100}'
PRINT 'FragRebuildPctLow in {NULL,0..100}'
PRINT 'MaxFragPctToRebuild in {NULL,0..100}'
PRINT 'defragType in {0,1,2}'
PRINT 'MinPages > 0'
PRINT 'Verbose in {0,1}'
PRINT 'Online in {0,1}'
select 5 as RESULTCODE, @TOTALINDEXESTOREBUILDANDREORGANIZE as TOTALINDEXESTOREBUILD,
@REBUILTWITHONLINEON as REBUILTWITHONLINEON, @REBUILTWITHONLINEOFF as REBUILTWITHONLINEOFF
return 5
end
--print parameter values in verbose mode
if(@VERBOSE=1)begin
PRINT CONVERT(varchar(30), GETUTCDATE(), 113)+' : Parameter values are :-'
PRINT ' @AllIndexTypes : '+CAST(@ALLINDEXTYPES as varchar)
PRINT ' @MaxRunTime : '+IIF(@MAXRUNTIME IS NULL, '<NULL>', CAST(@MAXRUNTIME as
varchar))
PRINT ' @FragRebuildPctHigh : '+CAST(@FRAGREBUILDPCTHIGH as varchar)
PRINT ' @FragRebuildPctLow : '+CAST(@FRAGREBUILDPCTLOW as varchar)
PRINT ' @MaxFragPctToRebuild : '+CAST(@MAXFRAGPCTTOREBUILD as varchar)
PRINT ' @DefragType : '+CAST(@DEFRAGTYPE as varchar)
PRINT ' @MinPages : '+CAST(@MINPAGES as varchar)
PRINT ' @Verbose : '+CAST(@VERBOSE as varchar)
PRINT ' @Online : '+CAST(@ONLINE as varchar)
PRINT ' '
end
declare @INDEXES table(SCHEMANAME SYSNAME,
TABLENAME SYSNAME,
INDEXNAME SYSNAME,
OLDFRAG int,
NEWFRAG int null,
PROCESSED bit)
declare @UPDATESTATISTICS table(SCHEMANAME SYSNAME,
TABLENAME SYSNAME,
INDEXNAME SYSNAME,
PROCESSED bit)
declare @ERRORS table(NUMBER int,
SEVERITY int,
STATE int,
ONLINEON bit,

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 31


STATEMENT NVarchar(2048)) ---Identify the Indexes that are fragmented and needs
rebuild/reOrg
declare @FRAGMENTATIONSCANSTART datetime=GETUTCDATE()
insert into @INDEXES
select SCHEMA_NAME(O.SCHEMA_ID), OBJECT_NAME(S.OBJECT_ID), I.NAME,
S.AVG_FRAGMENTATION_IN_PERCENT, null, 0
from SYS.DM_DB_INDEX_PHYSICAL_STATS(DB_ID(), NULL, NULL, NULL, NULL) S
JOIN SYS.OBJECTS O on(S.OBJECT_ID=O.OBJECT_ID)
JOIN SYS.INDEXES I on(S.OBJECT_ID=I.OBJECT_ID and S.INDEX_ID=I.INDEX_ID)
where S.AVG_FRAGMENTATION_IN_PERCENT>=@FRAGREBUILDPCTLOW -- defrag only if more than or
equal to x% fragmented
and S.AVG_FRAGMENTATION_IN_PERCENT<=@MAXFRAGPCTTOREBUILD -- defrag only if less
than or equal to x% fragmented
and I.TYPE in (1, @ALLINDEXTYPES+1)
-- (1,2) -- cannot defrag non-indexes(0-heap, 1- clustered, 2-nonclustered, 3-xml)
and S.PAGE_COUNT>=@MINPAGES -- select only if the index spans multiple pages
and O.NAME !='Attachment' -- Exclude Attachment table since Data Purging is going
on
order by S.AVG_FRAGMENTATION_IN_PERCENT desc
select @TOTALINDEXESTOREBUILDANDREORGANIZE=@@ROWCOUNT
select @FRAGMENTATIONSCANDURATIONINSECONDS=DATEDIFF(S, @FRAGMENTATIONSCANSTART,
GETUTCDATE()) -- Get all indexes that have a datetime column which are not set to be rebuild
insert into @UPDATESTATISTICS
select SCHEMA_NAME(T.SCHEMA_ID), T.NAME, I.NAME, 0
from SYS.INDEXES as I with(NOLOCK)
INNER JOIN SYS.INDEX_COLUMNS as IC with(NOLOCK)on I.OBJECT_ID=IC.OBJECT_ID AND
I.INDEX_ID=IC.INDEX_ID
INNER JOIN SYS.COLUMNS as C with(NOLOCK)on C.OBJECT_ID=IC.OBJECT_ID AND
C.COLUMN_ID=IC.COLUMN_ID
INNER JOIN SYS.TABLES T with(NOLOCK)on I.OBJECT_ID=T.OBJECT_ID
where IC.KEY_ORDINAL=1 AND C.SYSTEM_TYPE_ID=61 AND I.TYPE in (1, @ALLINDEXTYPES+1)AND NOT
EXISTS -- select only if not in the rebuild table
(select TABLENAME
from @INDEXES IND
where IND.SCHEMANAME=SCHEMA_NAME(T.SCHEMA_ID)collate DATABASE_DEFAULT AND
IND.TABLENAME=T.NAME collate DATABASE_DEFAULT and IND.INDEXNAME=I.NAME collate
DATABASE_DEFAULT)
order by T.NAME, I.NAME
select @TOTALSTATISTICSTOUPDATE=@@ROWCOUNT -- Emergency fix - Moved to the top so it will
run regardless of the rest
declare @MISCSTATSUPDATESTART datetime=GETUTCDATE()
if exists (select *
from SYS.OBJECTS
where OBJECT_ID=OBJECT_ID(N'[dbo].[SubscriptionTrackingDeletedObject]')and
TYPE in (N'U'))
update STATISTICS DBO.SUBSCRIPTIONTRACKINGDELETEDOBJECT
if exists (select *
from SYS.OBJECTS
where OBJECT_ID=OBJECT_ID(N'[dbo].[SubscriptionSyncEntryOfflineBase]')and TYPE
in (N'U'))
update STATISTICS DBO.SUBSCRIPTIONSYNCENTRYOFFLINEBASE
if exists (select *
from SYS.OBJECTS
where OBJECT_ID=OBJECT_ID(N'[dbo].[SubscriptionSyncEntryOutlookBase]')and TYPE
in (N'U'))
update STATISTICS DBO.SUBSCRIPTIONSYNCENTRYOUTLOOKBASE
select @MISCSTATSUPDATEBEFOREREBUILDINSECONDS=DATEDIFF(S, @MISCSTATSUPDATESTART,
GETUTCDATE())
if(@VERBOSE=1)begin
PRINT CONVERT(varchar(30), GETUTCDATE(), 113)+' : Statistics for
[SubscriptionTrackingDeletedObject], [SubscriptionSyncEntryOfflineBase] and
[SubscriptionSyncEntryOutlookBase] - Updated in:
'+cast(@MISCSTATSUPDATEBEFOREREBUILDINSECONDS as varchar(10))+' seconds'
end
-- end of Emergency fix
declare @SCHEMANAME SYSNAME, @TABLENAME SYSNAME, @INDEXNAME SYSNAME, @OLDFRAG int

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 32


declare @SQLREORG NVarchar(2048), @SQLREBUILDTEMPLATE NVarchar(2048), @sql
NVarchar(2048), @REINDEXCOMMENTS NVarchar(2048) ='', @ONLINEREBUILDFAILEDCOUNT int=0
declare @RETRY bit, @TRYONLINEON bit, @REORGANIZE bit --rebuild/reOrg Indexes
declare INDEXCURSOR cursor FORWARD_ONLY for
select SCHEMANAME, TABLENAME, INDEXNAME, OLDFRAG
from @INDEXES
order by OLDFRAG desc
open INDEXCURSOR
fetch NEXT from INDEXCURSOR
into @SCHEMANAME, @TABLENAME, @INDEXNAME, @OLDFRAG
WHILE((@@FETCH_STATUS=0)AND((GETUTCDATE()<@MAXTIME)OR(@MAXRUNTIME IS NULL)))begin
--init to default
select @sql=''
select @SQLREBUILDTEMPLATE=''
select @SQLREORG=''
select @REORGANIZE=1
select @SQLREORG=N'ALTER INDEX ['+@INDEXNAME+N'] ON
['+@SCHEMANAME+N'].['+@TABLENAME+N'] REORGANIZE WITH ( LOB_COMPACTION = ON ); ' -- default is
ON
select @SQLREORG=@SQLREORG+N' UPDATE STATISTICS ['+@SCHEMANAME+N'].['+@TABLENAME+N']
['+@INDEXNAME+N'] ' --REORGANIZE doesn't UPDATE STATISTICS, so adding explicitly
select @sql=@SQLREORG
if((@OLDFRAG>@FRAGREBUILDPCTHIGH OR @DEFRAGTYPE=2)AND(@DEFRAGTYPE<>1))begin
select @REORGANIZE=0
select @SQLREBUILDTEMPLATE=N'ALTER INDEX ['+@INDEXNAME+N'] ON
['+@SCHEMANAME+N'].['+@TABLENAME+N'] REBUILD WITH '+N'( PAD_INDEX = OFF,
STATISTICS_NORECOMPUTE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, SORT_IN_TEMPDB =
OFF, MAXDOP = '+CAST(@MAXDOP as nvarchar(10))+', ONLINE = '
select @sql=@SQLREBUILDTEMPLATE+N'ON )'
end
select @RETRY=1, @TRYONLINEON=1 --Always attempt Online rebuild irrespective of input
parameter @Online value
WHILE(@RETRY=1)begin
if(@VERBOSE=1)
PRINT CONVERT(varchar(30), GETUTCDATE(), 113)+' ['+CAST(@OLDFRAG as
varchar)+'%] : '+@sql
begin TRY
exec(@sql)
select @RETRY=0, @sql=''
if(@REORGANIZE=1)select @INDEXESREORGANIZED=@INDEXESREORGANIZED+1
else begin
if(@TRYONLINEON=1)select @REBUILTWITHONLINEON=@REBUILTWITHONLINEON+1 else
select @REBUILTWITHONLINEOFF=@REBUILTWITHONLINEOFF+1
end
end TRY
begin CATCH
insert into @ERRORS
select ERROR_NUMBER(), ERROR_SEVERITY(), ERROR_STATE(), @TRYONLINEON, @sql
if(@TRYONLINEON=1 and @REORGANIZE=0 and ERROR_NUMBER()=2725) --ONLINE rebuild
with 2725 error code
begin
-- Handle the possible exception below: rebuild index offline.
Only SQL2012 has THROW
--ErrorNumber ErrorMessage
--2725 An online operation cannot be performed for index '?'
because the index contains column '?' of data type text, ntext, image, varchar(max),
nvarchar(max), varbinary(max), xml,
-- or large CLR type. For a non-clustered index, the column
could be an include column of the index. For a clustered index, the column could be any
column of the table.
-- if DROP_EXISTING is used, the column could be part of a new
or old index. The operation must be performed offline.
select @ONLINEREBUILDFAILEDCOUNT=@ONLINEREBUILDFAILEDCOUNT+1
select @REINDEXCOMMENTS=N'*** '+CAST(@ONLINEREBUILDFAILEDCOUNT as
varchar(10))+N' ONLINE REBUILD operations failed due to BLOB dataType.'
if(@ONLINE=0)

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 33


select @REINDEXCOMMENTS=@REINDEXCOMMENTS+N' Attempting to REBUILD
OFFLINE... ***'
else
select @REINDEXCOMMENTS=@REINDEXCOMMENTS+N' Attempting to
REORGANIZE... ***'
if(@VERBOSE=1)PRINT @REINDEXCOMMENTS
if(@ONLINE=0) --Input Parameter 0 : First try ONLINE rebuild, if fails
then try OFFLINE rebuild
begin
select @sql=@SQLREBUILDTEMPLATE+N'OFF ) --retry after initial ONLINE
rebuild BLOB error'
select @TRYONLINEON=0, @RETRY=1
end
else begin
--(@Online is bit type, values can be only 0 or 1 )
--ONLINE rebuild failed, try REORG since input parameter @Online = 1,
which means ONLY ONLINE operations
select @sql=@SQLREORG+N' --retry after initial ONLINE rebuild BLOB
error'
select @TRYONLINEON=1, @REORGANIZE=1, @RETRY=1
end
end
else select @RETRY=0
end CATCH
end
update @INDEXES
set PROCESSED=1
where SCHEMANAME=@SCHEMANAME and TABLENAME=@TABLENAME and INDEXNAME=@INDEXNAME
fetch NEXT from INDEXCURSOR
into @SCHEMANAME, @TABLENAME, @INDEXNAME, @OLDFRAG
end
close INDEXCURSOR
deallocate INDEXCURSOR -- Update the statistics for any index that contains a datetime
column that wasn't rebuilt
declare UPDATECURSOR cursor FORWARD_ONLY for
select SCHEMANAME, TABLENAME, INDEXNAME from @UPDATESTATISTICS
open UPDATECURSOR
fetch NEXT from UPDATECURSOR
into @SCHEMANAME, @TABLENAME, @INDEXNAME
WHILE((@@FETCH_STATUS=0)AND((GETUTCDATE()<@MAXTIME)OR(@MAXRUNTIME IS NULL)))begin
select @sql=N'UPDATE STATISTICS ['+@SCHEMANAME+N'].['+@TABLENAME+N']
['+@INDEXNAME+N']'
if(@VERBOSE=1)PRINT CONVERT(varchar(30), GETUTCDATE(), 113)+' : '+@sql
begin TRY
exec(@sql)
select @STATISTICSUPDATED=@STATISTICSUPDATED+1
end TRY
begin CATCH
insert into @ERRORS
select ERROR_NUMBER(), ERROR_SEVERITY(), ERROR_STATE(), 1, @sql
end CATCH
update @UPDATESTATISTICS
set PROCESSED=1
where SCHEMANAME=@SCHEMANAME AND TABLENAME=@TABLENAME AND INDEXNAME=@INDEXNAME
fetch NEXT from UPDATECURSOR
into @SCHEMANAME, @TABLENAME, @INDEXNAME
end
close UPDATECURSOR
deallocate UPDATECURSOR
if(@VERBOSE=1)begin
PRINT ''
PRINT CONVERT(varchar(30), GETUTCDATE(), 113)+' : Starting rescan to identify current
fragmentation state...(this step is for verbose only)'
update @INDEXES
set NEWFRAG=AVG_FRAGMENTATION_IN_PERCENT
from SYS.DM_DB_INDEX_PHYSICAL_STATS(DB_ID(), NULL, NULL, NULL, NULL) S

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 34


JOIN SYS.OBJECTS O on(S.OBJECT_ID=O.OBJECT_ID)
JOIN SYS.INDEXES I on(S.OBJECT_ID=I.OBJECT_ID and S.INDEX_ID=I.INDEX_ID)
where SCHEMANAME=SCHEMA_NAME(O.SCHEMA_ID)collate DATABASE_DEFAULT and
TABLENAME=OBJECT_NAME(S.OBJECT_ID)collate DATABASE_DEFAULT and INDEXNAME=I.NAME collate
DATABASE_DEFAULT
PRINT CONVERT(varchar(30), GETUTCDATE(), 113)+' : rescan completed.'
end
declare @RESULTCODE int
if exists (select * from @INDEXES where PROCESSED=0)begin
PRINT 'Did not process all indexes due to @MaxRunTime constraint'
select @RESULTCODE=1
end
else if exists (select * from @UPDATESTATISTICS where PROCESSED=0)begin
PRINT 'Did not update all statistics due to @MaxRunTime constraint'
select @RESULTCODE=2
end
else begin
select @RESULTCODE=0
end
-- Return results
select @RESULTCODE as RESULTCODE, @TOTALINDEXESTOREBUILDANDREORGANIZE as
TOTALINDEXESTOREBUILD, @INDEXESREORGANIZED as INDEXESREORGANIZED, @REBUILTWITHONLINEON as
REBUILTWITHONLINEON, @REBUILTWITHONLINEOFF as REBUILTWITHONLINEOFF, @TOTALSTATISTICSTOUPDATE
as TOTALSTATISTICSTOUPDATE, @STATISTICSUPDATED as STATISTICSUPDATED,
@FRAGMENTATIONSCANDURATIONINSECONDS as FRAGMENTATIONSCANDURATIONINSECONDS,
@MISCSTATSUPDATEBEFOREREBUILDINSECONDS as MISCSTATSUPDATEBEFOREREBUILDINSECONDS,
@REINDEXCOMMENTS as REINDEXCOMMENTS
select * from @ERRORS
if(@VERBOSE=1)select * from @INDEXES order by OLDFRAG desc
if(@VERBOSE=1)select * from @UPDATESTATISTICS
return @RESULTCODE
end

Then schedule a job to execute stored procedure:


The job should run the following command:

use mycrm_MSCRM
set lock_timeout 20000
exec [p_DamsReindexAll] @FragRebuildPctLow=1, @MaxFragPctToRebuild=100, @DefragType=2

In the example the job is scheduled to run on specified time (11:30 PM to 5:45AM)

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 35


Stop reindexing job:
To stop the reindexing job, especially when running on a live database, set up a scheduled job to kick-off daily at,
for instance, 5:30 AM. This task will be responsible for stopping the mycrm_reindex job, using the script below:
USE msdb ;
GO
EXEC dbo.sp_stop_job N'mycrm_reindex' ;

Please discuss the DB backup strategy with your DBA while the reindexing job is running.

February 2024 CRM On-Premises to Dynamics 365 Online Migration Process 36

You might also like