In the System.Data namespace, there's a ConnectionState enumeration. This has values like Open, Closed, Connecting, Fetching to represent the state of a database connection.
I pondered on whether a connection which is "Fetching" is also "Open". It turns out that ConnectionState is declared with the FlagsAttribute - The mono DocComment for this enumeration says it best:
/// This enumeration has a FlagsAttribute that allows a bitwise combination of its member values.
Great - so now I can do something like:
if((connection.State & ConectionState.Open)==ConnectionState.Open) ...
Wrong! Further down the MSDN documentation for ConnectionState, tucked away in the Remarks section is the following paragraph:
The values in this enumeration are not designed to be used as a set of flags.
Great. So the question is, which of the database providers follow the FlagsAttribute, and which follow the documentation comment? Does SQL Server treat ConnectionState as flags? Does the managed Oracle provider? Does Oracle's ODP.Net provider treat it as flags? etc.
Certainly there are many people who treat it like flags. There are equally many people who ignore it.
I think I know this history behind this debacle - if anyone knows for sure, I'd like to know. If you actually look at the ConnectionState definition, you will see that ConnectionState.Closed has a value of 0. This flouts the .Net Design Guidelines and I expect it to be raised by FxCop/CodeAnalysis. Go ahead and read that link if you're not sure why bitwise comparison with 0 is a bad idea. This means there are a lot of bugs about due to the use of Bitwise comparison of ConnectionState.Closed. So I suspect that the System.Data team realized they'd made a mistake and was unable to retroactively remove the FlagsAttribute - so their approach was to document the issue in an obscure remark.