ReSharper show warning with SqlDataReader

Posted by Belousov Pavel on Stack Overflow See other posts from Stack Overflow or by Belousov Pavel
Published on 2010-06-14T07:28:53Z Indexed on 2010/06/14 7:32 UTC
Read the original article Hit count: 191

Filed under:
|
|
|

When I write something like this:

using (var connection = new SqlConnection("ConnectionString"))
{
    using(var cmd= new SqlCommand("Command"))
    {
        using (var reader = cmd.ExecuteReader())
        {
            while (reader.Read())
            {
            }
        }
    }
}

ReSharper shows warning on reader.Read(), and tells that reader can be null.

But in what cases can it be null? As I know if command returns nothing reader is not null, it only have nothing.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET