SyteLine SQL Blocking and Long Running Query Script Generator
When SyteLine forms freeze, a posting hangs or a job release takes minutes, the cause is often a blocked SQL session, not the application itself. This generator produces four read-only scripts that show who is blocked, who is blocking, which sessions hold open transactions and which requests run longest.
Fill in
Name of the database that hosts the _mst tables.
1. Blocked requests and who blocks them
-- Read-only diagnostic. Run in SSMS against the SQL Server instance.
SELECT TOP (25)
r.session_id,
r.blocking_session_id,
r.status,
r.wait_type,
r.wait_time AS wait_ms,
r.command,
DB_NAME(r.database_id) AS db_name,
s.login_name,
s.host_name,
s.program_name,
SUBSTRING(t.text, (r.statement_start_offset / 2) + 1,
((CASE r.statement_end_offset WHEN -1 THEN DATALENGTH(t.text) ELSE r.statement_end_offset END - r.statement_start_offset) / 2) + 1) AS running_statement
FROM sys.dm_exec_requests AS r
JOIN sys.dm_exec_sessions AS s ON s.session_id = r.session_id
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t
WHERE r.blocking_session_id <> 0
AND r.wait_time >= 5000
AND DB_NAME(r.database_id) = 'SL_App'
ORDER BY r.wait_time DESC;2. Head blockers (sessions blocking others but not blocked)
SELECT DISTINCT
r.blocking_session_id AS head_blocker_session,
s.login_name,
s.host_name,
s.program_name,
s.status,
s.last_request_start_time,
s.last_request_end_time,
t.text AS last_sql_text
FROM sys.dm_exec_requests AS r
JOIN sys.dm_exec_sessions AS s ON s.session_id = r.blocking_session_id
LEFT JOIN sys.dm_exec_connections AS c ON c.session_id = s.session_id
OUTER APPLY sys.dm_exec_sql_text(c.most_recent_sql_handle) AS t
WHERE r.blocking_session_id <> 0
AND r.blocking_session_id NOT IN (
SELECT session_id FROM sys.dm_exec_requests WHERE blocking_session_id <> 0
);3. Sessions with open transactions
SELECT st.session_id, s.login_name, s.host_name, s.program_name, s.status, s.last_request_end_time, DATEDIFF(SECOND, s.last_request_end_time, GETDATE()) AS idle_seconds FROM sys.dm_tran_session_transactions AS st JOIN sys.dm_exec_sessions AS s ON s.session_id = st.session_id WHERE s.is_user_process = 1 ORDER BY s.last_request_end_time;
4. Long running requests
SELECT TOP (25) r.session_id, r.total_elapsed_time / 1000 AS elapsed_s, r.cpu_time AS cpu_ms, r.logical_reads, r.status, r.wait_type, s.login_name, s.program_name, t.text AS sql_text FROM sys.dm_exec_requests AS r JOIN sys.dm_exec_sessions AS s ON s.session_id = r.session_id CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t WHERE r.session_id <> @@SPID AND s.is_user_process = 1 AND r.total_elapsed_time >= 30 * 1000 ORDER BY r.total_elapsed_time DESC;
These scripts only read dynamic management views and need VIEW SERVER STATE permission. Do not kill a session until you know what it is doing and who owns it. Test on a non-production system first and adapt the database filter for your instance.
Want blocking alerts that explain themselves?
An optional conversation about read-only monitoring of SyteLine SQL sessions with plain-language summaries for support teams.
Optional. The tool and every export work without this. No spam.
How to use the scripts
Fill in the database name and thresholds, then copy the output into SSMS and run the blocks one at a time while the slowdown is happening. Start with the first block to see waiting sessions, then the second to find the head blocker at the root of the chain. The program_name and host_name columns usually show whether the blocker is an application server, a scheduled process, a report job or a person running a query directly.
- Run during the incident, not afterwards
- Save results to Excel as evidence for the incident record
- Check the head blocker's last statement before deciding anything
Reading what you find
A single head blocker with many waiting sessions points to a long transaction, often a batch process or a form left open mid-transaction. Many sessions with a high wait_ms and no blocker point to resource issues instead, for example I/O or memory, and need different tools. Long idle sessions with open transactions are a classic pattern: the app holds locks while no statement is running, so the fix is in how the process commits.
Common mistakes
Killing the biggest victim rather than the head blocker achieves nothing, because the real blocker keeps going. Another mistake is changing indexes during an incident without evidence. Collect the data first, find the process, and then raise a targeted fix with the owner of the job, custom code or integration involved.
- Do not kill sessions without checking ownership
- Compare against a baseline from a normal day
- Look for scheduled jobs that overlap with business hours
Frequently Asked Questions
Do these scripts change anything in the database?
No. They only query dynamic management views and system catalogs. They require permission to view server state, and they should still be tested on non-production first because the views themselves can be heavy on very busy systems.
What does a head blocker mean?
It is a session that blocks others without being blocked itself. Resolving or finishing that session releases the chain. The second script lists these sessions with their login, host, application and last statement.
Will this work on SQL Server 2016 and later?
The views used here exist in current SQL Server versions, though column availability can vary slightly between releases. Check your version if a column is reported as invalid.
Is this specific to SyteLine tables?
The scripts are generic SQL Server diagnostics filtered to your SyteLine database. What makes them useful for SyteLine is interpreting the program names and statements against the application's processes.
If recurring SyteLine slowdowns are costing you hours, Netray can help build a monitored, read-only diagnostic that summarizes blockers in plain language for your support team.
Related Tools
SyteLine Database Tables Reference
Searchable lookup of the main SyteLine SQL tables, what each holds and its usual business key, for writing queries and reports.
Developer ToolsSyteLine Custom Table CREATE Script Generator
Creates a SQL Server CREATE TABLE script for a custom SyteLine table that follows the standard column and key conventions.
Infor SyteLineSyteLine Upgrade Regression Test Checklist
A practical regression checklist for SyteLine upgrades across business processes, customizations, reports and integrations.
Infor SyteLineSyteLine Downtime Cost Calculator
Quantify the hourly, monthly, and annual cost of SyteLine outages using your revenue, labor, and operational dependency profile.
More Developer Tools tools
See all- SyteLine IDO REST Request Generator
- SyteLine SQL Query Generator for Item, Job and Order Tables
- SyteLine Mongoose Framework Events Reference
- SyteLine Event Action Types Reference
- SyteLine Event Action Parameter Functions Reference
- SyteLine WinStudio Standard Form Events Reference
- SyteLine Mongoose API Options Reference
- SyteLine SQL User-Defined Data Types Reference
- SyteLine IDO Extension Class Method Generator
New to Infor SyteLine? Start with the Infor SyteLine guide and toolkit, or plan with Training Path Builder, ERP Certification Study Planner, Upgrade Path Planner.
Keep exploring
Free tools
- SQL Server Blocking and Deadlock Diagnostic Script GeneratorGenerate T-SQL to list blocked sessions, find the head blocker and its SQL text, spot idle open transactions and read recent deadlock graphs.
- SyteLine Open Purchase Order Query GeneratorBuilds a read-only SQL query for open and late PO lines in SyteLine 9/10, with a second query for vendor on-time delivery from PO receipts.
- SyteLine SQL Query Generator for Item, Job and Order TablesFill in site, item prefix, job status and date to produce read-only SQL for item master, jobs and open customer order lines.
ERP fixes and how-tos
- SyteLine Freezing for Everyone: Find the SQL Head BlockerWhen SyteLine freezes for many users, one blocking SQL session is often the cause. Find the head blocker, see its query, and decide whether to wait or kill.
- How to Improve SQL Server Performance for a Slow SyteLine ERP SystemFix a slow SyteLine ERP by tuning SQL Server: stale statistics, missing indexes, RCSI for blocking, IDO Runtime connection pooling, and index maintenance.
- SyteLine: Transaction Deadlocked, Chosen as the Deadlock VictimSyteLine users see 'chosen as the deadlock victim' on posting or MRP. Capture the deadlock graph, find the conflicting statements, and reduce them safely.
Guides
- Performance Best Practices for SyteLine Form ScriptsOptimize SyteLine form script performance. Avoid common bottlenecks in event handlers, reduce IDO calls, and build responsive forms in Infor CloudSuite Industrial.
- Effective Debugging Techniques for SyteLine ScriptsDebug SyteLine form scripts and global scripts effectively. Learn tracing, breakpoint strategies, and diagnostic tools for Infor CloudSuite Industrial script development.
- SyteLine Client vs Server Script Architecture GuideUnderstand SyteLine client vs server script execution. Form scripts, IDO methods, execution context, and when to use each for optimal performance.