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
Description
Rule S6966 flags
ServerConnection.ExecuteNonQuery()from Microsoft SQL Server Management Objects (SMO) with:However,
ServerConnection.ExecuteNonQueryhas no async counterpart. TheServerConnectionclass (fromMicrosoft.SqlServer.SqlManagementObjects) does not provide anExecuteNonQueryAsyncmethod.The analyzer likely matches the method name against
SqlCommand.ExecuteNonQueryAsyncfrom a different class hierarchy (System.Data.SqlClient/Microsoft.Data.SqlClient), but these are unrelated types.Reproducer
Product and Version
NuGet SonarAnalyzer.CSharp 10.23.0.137933