-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
Description
Description of the false positive
We have the following code:
/// <summary>
/// Creates a connection to database
/// </summary>
private static SqlConnection CreateConnectionToPublisherDB(Parameters parameters)
{
SqlConnectionStringBuilder connectionString = new SqlConnectionStringBuilder();
connectionString.DataSource = parameters.DatabaseServerName;
connectionString.InitialCatalog = parameters.DatabaseName;
SqlCredential credential = new SqlCredential(
parameters.DatabaseUserName,
parameters.DatabasePassword);
SqlConnection connection = new SqlConnection(connectionString.ConnectionString, credential);
connection.Open();
parameters.DatabasePassword.Dispose();
return connection;
}The cs/empty-collection rule flags connectionString with the following error.
The contents of this container are never initialized.
SqlConnectionStringBuilder does inherit from DbConnectionStringBuilder, which implements ICollection, and other collection interfaces, however these types specifically expose higher order properties like DataSource or DatabaseName which set the collection members internally. This warning is wrong for the case of code like SqlConnectionBuilder.
URL to the alert on the project page on LGTM.com
This issue was raised on a private LGTM instance unfortunately.