开发者

How to "get a new connection object, use it, close and dispose it each time you need", and handle the connection string?

开发者 https://www.devze.com 2022-12-15 19:32 出处:网络
As all we know, the connection string holds very important information... So while taking this strategy while developing .NET Windows-based applications:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消