Skip to content

Add SSMS-compatible connection settings support#193

Merged
ErikEJ merged 4 commits intomasterfrom
copilot/specify-connection-settings
Oct 24, 2025
Merged

Add SSMS-compatible connection settings support#193
ErikEJ merged 4 commits intomasterfrom
copilot/specify-connection-settings

Conversation

Copy link
Contributor

Copilot AI commented Oct 24, 2025

  • Explore repository structure and understand codebase
  • Identify all SqlConnection creation points
  • Review querysettings.sql file content
  • Create helper class to manage query settings (ConnectionSettingsHelper.cs)
  • Add StateChange event handler to apply settings when connection opens
  • Update LoadEngine.cs to use the new handler (3 locations)
  • Update ParamWindow.cs to use the new handler
  • Update DatabaseSelect.cs to use the new handler
  • Update ConnectionInfo.cs to use the new handler
  • Configure project files to include querysettings.sql in build output
  • Validate implementation with code review
  • Document the solution in README.md
  • Address PR review feedback:
    • Add semicolons to all SET statements in README and ConnectionSettingsHelper
    • Replace double-checked locking with Lazy pattern
    • Add exception logging instead of swallowing errors
    • Extract duplicate default settings to a constant

Summary

All requested changes have been implemented. The solution now:

  • Uses thread-safe Lazy pattern for settings initialization
  • Adds semicolons to all SET statements per SQL best practices
  • Logs exceptions for better debuggability
  • Follows DRY principle with extracted DefaultSettings constant
Original prompt

This section details on the original issue you should resolve

<issue_title>Specify connection settings</issue_title>
<issue_description>Right now, the main difference between executing a query in SQL Query Stress and SSMS is that SQS does not have ARITHABORT enabled. Pictured below are a couple stored procedure executions from an SSMS tab, and then via SQS.

Image

I understand why it behaves this way, but it would be nice to be able to specify connection settings like you can in SSMS, so things are a bit less wiggly if you're switching between the two.

SSMS options (Tools > Options > Query Execution > SQL Server)

ANSI:
Image

Advanced:
Image

Thank you</issue_description>

<agent_instructions>Proposed solution:

For the CommandText property below, read the contents of the querysettings.sql file

You can create an event handler for the Connection StateChange and have it set the property when the connection changes from Closed to Open as follows:

protected static void OnStateChange(object sender, StateChangeEventArgs args)
{
if (args.OriginalState == ConnectionState.Closed
&& args.CurrentState == ConnectionState.Open)
{
using (SqlCommand _Command = ((SqlConnection)sender).CreateCommand())
{
_Command.CommandType = CommandType.Text;
_Command.CommandText = "SET ARITHABORT ON;";

    _Command.ExecuteNonQuery();
}

}
}
With that in place, you only need to add the following to each place where you create a SqlConnection instance:

_Connection.StateChange += new StateChangeEventHandler(OnStateChange);</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@ErikEJ @erikdarlingdata Could we start with a text file with just the settings baked in? (That would then be used with each connection) ? @ErikEJ https://dba.stackexchange.com/a/95090/9320 @ErikEJ @erikdarlingdata Cool, I will add the settings to each open connection next. @ErikEJ Actually. Let me ask Copilot for help.

@copilot

Proposed solution:

For the CommandText property below, read the contents of the querysettings.sql file

You can create an event handler for the Connection StateChange and have it set the property when the connection changes from Closed to Open as follows:

protected static void OnStateChange(object sender, StateChangeEventArgs args)
{
if (args.OriginalState == ConnectionState.Closed
&& args.CurrentState == ConnectionState.Open)
{
using (SqlCommand _Command = ((SqlConnection)sender).CreateCommand())
{
_Command.CommandType = CommandType.Text;
_Command.CommandText = "SET ARITHABORT ON;";

        _Command.ExecuteNonQuery();
    }
}

}
With that in place, you only need to add the following to each place where you create a SqlConnection instance:

_Connection.StateChange += new StateChangeEventHandler(OnStateChange);

@ErikEJ @copilot

Fixes #191


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Add option to specify connection settings in SQL Query Stress Add SSMS-compatible connection settings support Oct 24, 2025
Copilot AI requested a review from ErikEJ October 24, 2025 11:29
@ErikEJ
Copy link
Owner

ErikEJ commented Oct 24, 2025

@erikdarling Not too shabby!

@ErikEJ ErikEJ requested a review from Copilot October 24, 2025 11:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds SSMS-compatible connection settings support to SQL Query Stress to ensure consistent query execution behavior between the tool and SQL Server Management Studio. The key missing setting was ARITHABORT ON, which could cause different execution plans and performance characteristics.

Key Changes:

  • Created ConnectionSettingsHelper class to automatically apply SSMS-compatible connection settings using a StateChange event handler pattern
  • Updated all SqlConnection instantiation points across 5 files to attach the event handler
  • Configured both GUI and CLI projects to include querysettings.sql file in build output

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/SQLQueryStress/ConnectionSettingsHelper.cs New helper class implementing thread-safe lazy loading of SQL connection settings from file with SSMS-compatible defaults
src/SQLQueryStress/LoadEngine.cs Added event handler attachment at 3 connection creation points (command execution, pool init, worker threads)
src/SQLQueryStress/ParamWindow.cs Attached event handler for parameter query connections
src/SQLQueryStress/DatabaseSelect.cs Attached event handler for database listing connections
src/SQLQueryStress/ConnectionInfo.cs Attached event handler for connection testing
src/SQLQueryStress/SQLQueryStress.csproj Configured to copy querysettings.sql to output directory
src/SqlQueryStressCLI/sqlstresscmd.csproj Configured to copy querysettings.sql and link ConnectionSettingsHelper.cs
README.md Added documentation for connection settings feature and customization instructions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Owner

@ErikEJ ErikEJ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Please make the requested changes

Copy link
Contributor Author

Copilot AI commented Oct 24, 2025

@copilot Please make the requested changes

Done in commit d56e50e. All requested changes have been implemented:

  • Added semicolons to all SET statements
  • Replaced double-checked locking with Lazy pattern
  • Added exception logging
  • Extracted duplicate default settings to a constant

Copilot AI requested a review from ErikEJ October 24, 2025 12:06
@ErikEJ ErikEJ marked this pull request as ready for review October 24, 2025 12:07
@ErikEJ ErikEJ merged commit 666a07c into master Oct 24, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Specify connection settings

3 participants