As all we know, the connection string holds very important information...
So while taking this strategy while developing .NET Windows-based applications:
get a new connection object, use it, close and dispose it each time 开发者_开发问答you need
How can I handle the connection string within the application?
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.
精彩评论