Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CommandBehavior.SingleRow causing DB connection to remain open?

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.

like image 968
Ender Avatar asked Oct 15 '25 10:10

Ender


1 Answers

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

Dim reader As SqlDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection Or CommandBehavior.SingleRow)
like image 130
Joel Beckham Avatar answered Oct 18 '25 09:10

Joel Beckham



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!