Connection Issues
Connection timeout errors during test startup
Connection timeout errors during test startup
Symptom
Tests fail to start or multiple threads fail immediately with connection timeout errors.Root Cause
TheConnectionTimeout setting (default: 15 seconds in QueryStressSettings.cs:119) controls how long the client waits to establish a connection. When using many threads, SQL Server may not accept connections fast enough.Solution
-
Increase ConnectionTimeout:
- Recommended: 30-60 seconds for high thread counts (>50 threads)
- The setting applies to all connections in the test
-
Verify SQL Server connection limits:
-
Check connection pooling is enabled:
- Verify
EnableConnectionPooling = true(default in QueryStressSettings.cs:121) - Pooling is essential for multi-threaded testing
- Verify
-
Reduce initial thread count:
- Start with fewer threads and gradually increase
- LoadEngine pre-allocates MinPoolSize = threads (LoadEngine.cs:47)
Prevention
Connection pool exhaustion during test
Connection pool exhaustion during test
Symptom
“Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool.”Root Cause
The connection pool is configured withMinPoolSize = MaxPoolSize = threads (LoadEngine.cs:46-48). If connections aren’t being properly closed, the pool can be exhausted.Solution
-
Verify proper connection handling:
- LoadEngine uses
usingstatements (LoadEngine.cs:382) to ensure disposal - Connections are explicitly closed after each iteration (LoadEngine.cs:456)
- LoadEngine uses
-
Check for blocking queries:
- Long-running queries hold connections longer
- Set appropriate
CommandTimeoutto prevent indefinite holds (default: 0 = infinite)
-
Clear connection pools:
- LoadEngine calls
ClearAllPools()on cancellation (LoadEngine.cs:194) - Restart the application if pools are corrupted
- LoadEngine calls
'A severe error occurred on the current command'
'A severe error occurred on the current command'
Symptom
Intermittent severe errors, connection dropped, or attention errors during execution.Root Cause
Most commonly caused by query timeouts or resource exhaustion on SQL Server.Solution
-
Set reasonable CommandTimeout:
- Default is 0 (infinite), which can cause issues
- Recommended: 30-120 seconds depending on expected query duration
-
Enable KillQueriesOnCancel:
- Default:
true(QueryStressSettings.cs:125) - Ensures queries are cancelled when you stop the test
- Uses timer to call
SqlCommand.Cancel()(LoadEngine.cs:322-340)
- Default:
-
Check SQL Server resources:
- Memory pressure
- TempDB contention
- Lock escalation
Thread and Cancellation Issues
Test doesn't stop when cancelled
Test doesn't stop when cancelled
Symptom
Clicking “Cancel” doesn’t stop the test immediately, or threads hang indefinitely.Root Cause
Threads are running queries that don’t respond to cancellation tokens.KillQueriesOnCancel Setting
This setting (QueryStressSettings.cs:54, default:true) controls aggressive query cancellation.When enabled (recommended):- A timer checks every 2 seconds if cancellation is pending (LoadEngine.cs:324)
- Calls
SqlCommand.Cancel()to request SQL Server terminate the query (LoadEngine.cs:334) - Threads are given 5 seconds to exit gracefully (LoadEngine.cs:190)
- After 5 seconds, threads are forcefully interrupted (LoadEngine.cs:191)
- Threads wait for queries to complete naturally
- Can take a long time if queries are slow or blocked
Solution
- Ensure KillQueriesOnCancel is enabled (default)
- Wait up to 5 seconds for graceful thread termination
- If threads still hang: Check for SQL Server blocking
Thread cancellation during query delay
Thread cancellation during query delay
Symptom
When usingDelayBetweenQueries, tests take a long time to cancel.Root Cause
The delay usesTask.Delay() which must respect the cancellation token (LoadEngine.cs:491).How It Works
Solution
This is working as designed. The cancellation token properly interrupts delays, so you should see responsive cancellation even with long delays.If experiencing issues:- Ensure you’re using a recent version of SQL Query Stress
- Check that
KillQueriesOnCancel = true
Query Execution Errors
Parameter-related errors
Parameter-related errors
Query works in SSMS but fails in SQL Query Stress
Query works in SSMS but fails in SQL Query Stress
Symptom
Your query executes successfully in SQL Server Management Studio but fails during stress testing.Root Cause
SQL Query Stress applies SSMS-compatible connection settings (documented in README.md:33-43) that may expose issues not visible in isolation.Common Issues
-
Connection settings differences:
- SQL Query Stress sets
ARITHABORT ON(matches SSMS) - Sets
QUOTED_IDENTIFIER ON - Sets
ANSI_NULLS ONThese settings can affect query plans and behavior.
- SQL Query Stress sets
-
Timeout differences:
- CommandTimeout default is 0 (infinite) in SQL Query Stress
- SSMS default is typically 0 as well, but can be configured differently
-
Connection context:
- SQL Query Stress sets
CurrentLanguage = "English"(LoadEngine.cs:49) - Date formats and error messages use English
- SQL Query Stress sets
Solution
- Review querysettings.sql in the application directory
- Test query with same SET options in SSMS:
- Check query plan differences using
SET STATISTICS PROFILE ON
Inconsistent results or deadlocks
Inconsistent results or deadlocks
Symptom
- Random deadlock errors (Error 1205)
- Some iterations succeed, others fail
- Results vary between test runs
Root Cause
Concurrent execution creating lock contention or race conditions.Solution
-
Review query isolation level:
- Default is READ COMMITTED
- Consider if your test should use snapshot isolation:
-
Analyze deadlock patterns:
- Enable trace flag 1222 for deadlock details
- Check SQL Server error log
- Identify conflicting resources
-
Reduce concurrency temporarily:
- Lower thread count to isolate issue
- If deadlocks disappear with fewer threads, this confirms lock contention
-
Add query hints if appropriate:
WITH (NOLOCK)for read-only queries (be aware of dirty reads)WITH (READPAST)to skip locked rowsWITH (ROWLOCK)to prevent lock escalation
Statistics and Results Issues
Logical reads or time statistics not appearing
Logical reads or time statistics not appearing
Symptom
The statistics columns remain at 0 or blank during test execution.Root Cause
Statistics collection is disabled or the InfoMessage event handler isn’t capturing output.How Statistics Work
When enabled (LoadEngine.cs:139-144):SET STATISTICS IO ONand/orSET STATISTICS TIME ONis executed- SQL Server sends statistics as InfoMessage events
- The InfoMessage handler parses messages using regex (LoadEngine.cs:278-287)
- Extracted values populate QueryOutput (LoadEngine.cs:352, 361-362)
Solution
-
Enable statistics collection:
CollectIoStats = true(default in QueryStressSettings.cs:122)CollectTimeStats = true(default in QueryStressSettings.cs:123)
-
Verify query produces statistics:
- Some queries (like
SELECT @@VERSION) don’t generate IO statistics - DDL statements may not produce expected statistics
- Some queries (like
-
Check for query errors:
- If the query fails, statistics aren’t collected
- Review the Exceptions column in results
-
Test statistics manually in SSMS:
Execution time seems wrong
Execution time seems wrong
Symptom
Reported execution times don’t match expectations or SQL Server metrics.What Gets Measured
The LoadEngine uses aStopwatch (LoadEngine.cs:295) that starts immediately before query execution and stops after:- ForceDataRetrieval = false: After
ExecuteNonQuery()returns (LoadEngine.cs:432) - ForceDataRetrieval = true: After all rows are read from all result sets (LoadEngine.cs:418-428)
- Query execution on server
- Network transfer
- Client-side data processing
Solution
-
Compare with SQL Server statistics:
- Enable
CollectTimeStatsto see server-side elapsed time - Client time will always be >= server time due to network overhead
- Enable
-
Consider ForceDataRetrieval setting:
- If
true, time includes reading all rows - Large result sets will show significantly longer times
- If
-
Check for network latency:
- Run test from same machine as SQL Server
- Use
SELECT @@SERVERNAMEto verify server
-
Account for statistics collection overhead:
- Parsing InfoMessages adds minimal time (<1% typically)
- Disable to verify if you suspect overhead
Getting Help
If you’re still experiencing issues:- Check GitHub issues: SQLQueryStress Issues
- Review source code: LoadEngine.cs contains the complete execution logic
- Submit detailed bug report: Include query, settings, error messages, and SQL Server version