web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

CRM 8.2 on prem, simple fetch xml query locks database?

(3) ShareShare
ReportReport
Posted on by 26
Hello, 
 
We found out that simple fetch xml query bellow was locking the database. The fetchxml bellow was found in the SQL as the head blocking process 4 times in 1 hour. Blocks were ranging from 2 mins, 28 mins, 38 mins and up to 57 mins.
Nothing seems unusual in the Execution plan of the query, looks normal, very little data is passed. 
Calling this from a C# plugin which is reading little data, one or two rows of data, nothing special, just creates one record in the CRM 8.2 on prem. 
Plugin runs only once, is synchronous and is registered on preOperation.
 
Has anyone else experienced such scenario and solved it? 
 
Answers will be highly appreciated
 
 
<fetch output-format='xml-platform' mapping='logical' distinct='false'>
                                  <entity name='entity1'>
                                    <attribute name='attribute1' />
                                    <attribute name='attribute2' />
                                    <order attribute='attribute1' descending='false' />
                                    <filter type='and'>
                                      <filter type='or'>
                                        <condition attribute='attribute1' operator='eq' value='someValue' />
                                        <condition attribute='attribute1' operator='eq' value='someValue' />
                                      </filter>
                                    </filter>
                                    <link-entity name='entity2' from='entity2id' to='entity2id' alias='ent'>
                                      <filter type='and'>
                                        <condition attribute='attribute3' operator='eq' value='{id}' />
                                      </filter>
                                    </link-entity>
                                  </entity>
                                </fetch>
I have the same question (0)
  • Verified answer
    Daivat Vartak (v-9davar) Profile Picture
    7,835 Super User 2025 Season 2 on at
    Hello crm 8.2 developer,
     
    This is a challenging situation, especially with a seemingly simple FetchXML query causing significant database locking. Let's break down the potential causes and troubleshooting steps, considering the context of your CRM 8.2 on-prem environment:
     
    Understanding the Problem:
    • Blocking: The fact that this query is identified as a head blocking process means it's holding locks on resources that other processes need, causing them to wait.
    • Duration: The long durations of the blocks (28-57 minutes) are critical. This indicates a severe performance bottleneck.
    • Simplicity: The query itself appears straightforward, suggesting the issue might be related to underlying data, indexes, or SQL Server configuration.
    • PreOperation Plugin: Running synchronously in pre-operation means the lock is held before the main transaction is committed.
     
    Potential Causes and Troubleshooting:
    1. Index Fragmentation/Missing Indexes:
      • Even with small data volumes, fragmented or missing indexes on entity1 or entity2 can lead to inefficient query execution and prolonged lock durations.
      • Action:
        • Analyze the execution plan in SQL Server Management Studio (SSMS) closely. Look for table scans, index scans with high logical reads, and missing index recommendations.
        • Rebuild or reorganize indexes on entity1 and entity2, especially attribute1, attribute2, and attribute3.
        • Ensure appropriate indexes exist for the filter conditions.
    2. Parameter Sniffing Issues:
      • SQL Server might be caching an execution plan based on specific parameter values (someValue, {id}). If those values result in a poor execution plan for other values, it can lead to performance problems.
      • Action:
        • Try adding OPTION (RECOMPILE) to the FetchXML query (if possible through your plugin). This forces SQL Server to generate a new execution plan each time.
        • If possible, test the query in SSMS with different values for the filter conditions to see if performance varies significantly.
        • If the issue is parameter sniffing, you may need to adjust the query or SQL Server configuration.
    3. Lock Escalation:
      • SQL Server might escalate row-level locks to page or table-level locks if a large number of rows are being accessed. This can lead to blocking.
      • Action:
        • Check the lock escalation settings for the relevant tables.
        • Consider optimizing the query to reduce the number of rows accessed.
    4. Transaction Isolation Levels:
      • The transaction isolation level can affect how locks are acquired and released.
      • Action:
        • Verify the transaction isolation level used by the plugin and the CRM application.
        • Consider using a less restrictive isolation level if appropriate.
    5. CRM Platform Issues:
      • While less likely, there might be underlying issues with the CRM 8.2 platform itself.
      • Action:
        • Check for any known issues or hotfixes related to FetchXML queries or database locking in CRM 8.2.
        • Ensure your CRM environment is up to date with the latest patches.
    6. SQL Server Resource Contention:
      • If the SQL Server is under heavy load, resource contention (e.g., CPU, memory, I/O) can lead to performance problems and blocking.
      • Action:
        • Monitor SQL Server performance using Performance Monitor or other tools.
        • Identify any resource bottlenecks and take appropriate action.
    7. Link Entity Performance:
      • Even though it is a simple link entity, if there is a large amount of data in entity2, and there is no proper indexing, this could be the source of the problem.
      • Action:
        • Verify the indexes in entity2.
        • Verify the amount of data in entity2.
     
    Debugging Steps:
    1. Enable SQL Server Profiler:
      • Capture a trace of the SQL Server activity during the blocking period. This will provide detailed information about the locks being held and the queries being executed.
    2. Use SSMS Activity Monitor:
      • Monitor the active processes and locks in SSMS to identify the blocking queries.
    3. Review CRM Trace Logs:
      • Enable tracing in CRM to capture detailed information about the plugin execution.
    4. Isolate the Plugin:
      • Disable other plugins and customizations to rule out any conflicts.
    5. Test the FetchXML Independently:
      • Execute the FetchXML query directly in SSMS to see if it causes blocking outside of the plugin context.
     
    Key Considerations:
    • On-Prem Environment: On-prem environments often have unique configurations and challenges.
    • CRM 8.2: This version is older, so there might be limitations or known issues.
    • Plugin Context: The plugin's execution context can influence database behavior.
     
    By systematically investigating these potential causes and using the debugging steps, you should be able to pinpoint the root cause of the database locking issue.
     
    If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more.
    If you have further questions, please feel free to contact me.
     
    My response was crafted with AI assistance and tailored to provide detailed and actionable guidance for your Microsoft Dynamics 365 query.
     
    Best Regards,
    Daivat Vartak
  • Suggested answer
    Alex KaSi Profile Picture
    41 on at
    As you're using a pretty old version without the fetchXML performance optimizations from the last years you can try using the no-lock attribute:
     
    <fetch mapping=’logical’ no-lock=’true’>
     
  • Vahid Ghafarpour Profile Picture
    12,166 Super User 2025 Season 2 on at
    If any of the responses helped resolve your issue, please take a moment to mark the best answer. This helps others in the community quickly find solutions to similar problems.

    To do this, simply click the "Does this answer your question?" button on the most helpful response and like the helpful posts. If your issue is still unresolved, feel free to provide more details so the community can assist further!

    Thanks for being an active part of the Dynamics 365 Community! 😊

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans