views:

223

answers:

1

Recently I was working on a project in VB.NET, and I was encountering a mysterious problem with some of the DB connections. This was a project that I inherited from someone else and they had used something like this:

Dim reader As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection And CommandBehavior.SingleRow)
//after reading data
reader.Close()

It appears as though this was causing the connection to not close properly all the time. I've removed the CommandBehavior.SingleRow, and it seems to be working ok now, but I was wondering if anyone else has encountered this? Does anyone know why that would not work? I've seen CommandBehaviors combined in this way before, but it has never caused that problem before.

+2  A: 

When combining flags, use the OR operator instead of AND:

Dim reader As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection Or CommandBehavior.SingleRow)
Joel