In the following method i get the warning:
warning : CA2000 : Microsoft.Reliability : In method 'AvdfileCache.AddPartTableGaugeData(long, long)', call System.IDisposable.Dispose on object 'cmdGaugeData' before all references to it are out of scope.
private long AddPartTableGaugeData(long lDBIdAvdFile, long lValue)
{
long lDBIdInserted = -1;
using (SQLiteCommand cmdGaugeData = new SQLiteCommand(_connection))
{
cmdGaugeData.CommandText = GetKnownSql(enuKnownSqlStatementKeys.AVDJOURN_GAUGEDATA_INSERT);
cmdGaugeData.Parameters.AddWithValue(null, lDBIdAvdFile);
cmdGaugeData.Parameters.AddWithValue(null, lValue);
cmdGaugeData.ExecuteNonQuery();
lDBIdInserted = _connection.LastInsertRowId;
}
return lDBIdInserted;
}
I thought because of the using-Statement it's guaranteed that cmdGaugeData
gets disposed under all circumstances, so why do I still get this warning?
EDIT: by now I think this is a bug in the analyzer. I have to admit that the above code is a stripped variant of my real code (actually I have more parameters in my real code) and while trying to figure out when the warning appears i come to the following:
private long AddPartTableGaugeData(long lDBIdAvdFile, AVDPart part)
{
long lDBIdInserted = -1;
using (SQLiteCommand cmdGaugeData = new SQLiteCommand(_connection))
{
cmdGaugeData.CommandText = GetKnownSql(enuKnownSqlStatementKeys.AVDJOURN_GAUGEDATA_INSERT);
cmdGaugeData.Parameters.AddWithValue(null, "SVal_1".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_2".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_3".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_4".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_5".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_6".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_7".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_8".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_9".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_10".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_11".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_12".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_13".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_14".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_15".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_16".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_17".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_18".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_19".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_20".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_21".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_22".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_23".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_24".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_25".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_26".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_27".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_28".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_29".ToString());
cmdGaugeData.Parameters.AddWithValue(null, "SVal_30".ToString());
cmdGaugeData.ExecuteNonQuery();
}
lDBIdInserted = _connection.LastInsertRowId;
return lDBIdInserted;
}
This code brings the warning again, BUT:
- No Warning, when I remove the
ToString
-Calls (just pass inSVal_xx
as Parameter) - No Warning, when I use 29 time
ToString
, the 30th parameter withToString
generates the Warning
So any further hints on that?