open a db connection in a constructor ?

  • Thread starter Thread starter Author
  • Start date Start date
Peter said:
In your opinion is it a "problem" at all, or is it ok to do this?

I would be willing to do it for smaller projects. Not for the
big stuff.

But remember: free advice is worth every cent you pay for it ! :-)
What I don't like about it is that (1) the connection to the database
is now open until the business layer closes it;

Not a serious problem in my opinion.
and (2) the business
layer has to have knowledge of the data layer (and data source) to be
able to extract the data, either by use of column names or indices -
meaning the business layer has to have knowledge of the sql which
extracted the data in the first place, and my opinion is that this
knowledge belongs in the data layer, not the business layer.

But I agree that this is a problem !
But it *is* recommeded by Microsoft - so it could be it is a good way
to get data.

MS is not perfect. And some things has been done giving priority to
being simple. The inheritance from Mort !
Seems pointless to have a business layer though.

That is another point. Someone preaches 3 layers as the only way. In
reality the number of layers should reflect the problem to be solved.
Some simple apps is actually fine with 2. But 3 to 4 are more common.

Arne
 
But it *is* recommeded by Microsoft - so it could be it is a good way
to get data.

No, it's not. It can't be, that recommender should lose their job
immediately. That programming rubbish is the reason there are so many
resource leaks in web applications. I have yet to come across a reason why
returning an open cursor to a caller is valid.

--

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Download OWC Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $15.00
Need a free copy of VSTS 2008 w/ MSDN Premium?
http://msmvps.com/blogs/alvin/Default.aspx
 
Back
Top