I have started to get a series of CA2202 and CA2000 warnings in VS2010 which I cannot account for. They seem to say that I am calling Dispose more than once on a series of statements. Here is a sample block which demos the logic.
using (SqlConnection dCon = UTILITY.MakeSQLConnection(KNOWN_SQL_SERVERS.NEXGENAM))
{
try
{
if (dCon != null) gaList = READDB(dCon);
}
catch (Exception)
{
throw;
}
finally
{
if ((dCon != null) &&
(dCon.State != ConnectionState.Closed)) dCon.Close();
}
}
I do not see a single dispose in my code. The warning/errors seem to imply that the Close() statement is a call to dispose. I am under the impression that it marks the object available for disposal but does not actually call the dispose method. While technically the Close is not required, I come from the school of "If I open it, I close it". My understanding indicates that the using block will perform the actual disposal of the "dCon" object.
(The "MakeSQLConnection" creates a SQL connection to the specified server and either returns a open connection or NULL)
Anyone see something I am missing? While I could supress these error/warning, I would prefer to repair the problem assuming it exists.
Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.