Skip to content

NET-3859 Fix S6966 FP: ServerConnection.ExecuteNonQuery (SMO) has no async counterpart #9803

Open

Description

@tsimbalar

Description

Rule S6966 flags ServerConnection.ExecuteNonQuery() from Microsoft SQL Server Management Objects (SMO) with:

Await ExecuteNonQueryAsync instead.

However, ServerConnection.ExecuteNonQuery has no async counterpart. The ServerConnection class (from Microsoft.SqlServer.SqlManagementObjects) does not provide an ExecuteNonQueryAsync method.

The analyzer likely matches the method name against SqlCommand.ExecuteNonQueryAsync from a different class hierarchy (System.Data.SqlClient / Microsoft.Data.SqlClient), but these are unrelated types.

Reproducer

using Microsoft.Data.SqlClient;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;

async Task RunSqlScript(string connectionString, string sqlScript)
{
    await using var connection = new SqlConnection(connectionString);
    await connection.OpenAsync();
    var server = new Server(new ServerConnection(connection));
    server.ConnectionContext.ExecuteNonQuery(sqlScript); // S6966: Await ExecuteNonQueryAsync instead.
}

Product and Version

NuGet SonarAnalyzer.CSharp 10.23.0.137933

Activity

  1. martin-strecker-sonarsource commented on Jun 3, 2026

    @martin-strecker-sonarsource
    Contributor

    Hi @tsimbalar, thanks for the report!

    A quick note before we dig in: the linked docs page targets sql-smo-160 (and Microsoft Learn currently defaults to sql-smo-172). However, async overloads of ExecuteNonQuery, ExecuteReader, ExecuteScalar, and ExecuteWithResults were added to ServerConnection in Microsoft.SqlServer.SqlManagementObjects v181.19.0 (April 2025, ships with SSMS 22):

    So whether this is a true FP depends on which SMO version your project references. Could you share the Microsoft.SqlServer.SqlManagementObjects version from your csproj/packages.lock.json?

    • If you're on >= 181.19.0: the rule is actually correct — there is an ExecuteNonQueryAsync you can await, and the Microsoft Learn page just hasn't caught up.
    • If you're on < 181.19.0 (e.g. v160/v172): we'll dig into why the analyzer is flagging it despite no async counterpart being present on ServerConnection — that would be a genuine FP and we'll get it fixed.

    Thanks!

  2. changed the title [-]Fix S6966 FP: ServerConnection.ExecuteNonQuery (SMO) has no async counterpart[/-] [+]NET-3859 Fix S6966 FP: ServerConnection.ExecuteNonQuery (SMO) has no async counterpart[/+] on Jun 3, 2026
  3. github-actions commented on Jun 3, 2026

    @github-actions
    Contributor

    Internal ticket NET-3859

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions