views:

23

answers:

1

As all we know, Connection string is a very important info....

So taking this strategy while developing .net win-based application : "get a new connection object, use it, close and dispose it each time you need", How to handle connection string within the application?

+1  A: 

Usually, I would have a connection factory method centrally in the data layer. Everyone who needs a connection, should call that factory method; in order to ensure that all connections are created equal - and to avoid throwing magic strings around in the source code.

Example:

DBConnection conn = DBFactory.CreateConnection();

The only place you need to know about the connection string and where to get it, would be in that one method.

driis
@driis, hhhm, ok you're right. But as you certainly know, this piece of code in in DAL, my question is: if we have got the connection string in GUI layer, how do we do trandfer it to the DAL? and more important, what about it if we take advantage of using block in c# for connection object?
odiseh