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
- SAP Sales Order ABAP SELECT Generator (VBAK, VBAP, VBFA)
- SAP Sales Order Create BAPI ABAP Generator (BAPI_SALESORDER_CREATEFROMDAT2)
- SAP ABAP Open Items SELECT Generator
- SAP ACDOCA SQL Query Generator
- SAP QM Inspection Lot ABAP SELECT Generator
- SAP Quality Notification Pareto SQL Query Generator
- SAP QM Usage Decision BAPI Skeleton