Skip to content

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

@tsimbalar

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions