There is probably is simple fix for this but I currently have code similar to
dim dr as dbDataReader
try
dr = connection.getDataReader(sql_str)
Catch ex as sqlClientException
log.error(ex)
finally
if not IsNothing(dr) then
dr.close
end if
end try
However Visual Studio still warns me that the
if not IsNothing(dr) then
dr.close
end if
Can cause a NullReferenceException. What is the best way to mitigate this? I can't move the declaration into the try block.
Explicitly initialize the dr declaration to Nothing as such:
Dim dr As DbDataReader = Nothing
And the warning will disappear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With