如何处理在数据访问层连接(.NET) [英] How to handle connections in data access layer ( .net )

查看:97
本文介绍了如何处理在数据访问层连接(.NET)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜 我写一个数据访问层。我感到困惑的系统管理连接。 我知道,.NET使用连接池。但我不希望打开,并在所有DML操作或所有SQL查询的关闭数据库连接。我该如何处理呢?何时何地(也许在它使用的数据访问层和数据访问层全球ASAX)的连接应加以管理?

Hi I am writing a data access layer. I am confused about managing connections in the system. I know that .net uses connection pooling. But I do not want to open and close database connections in all dml operations or in all sql query's. How can I handle this? Where and when ( maybe in global asax which uses data access layer or in the data access layer ) the connections should be managed?

推荐答案

除非你正在运行一个批处理语句,则应该打开和关闭的SQL连接,为每个查询。

You should open and close sql connections for each query, unless you are running a batch of statements.

打开晚了,提前关门是如何你应该总是处理数据库的连接。

"Open late, close early" is how you should always handle database connections.

如果你要它在传统的方式(使自己的查询),MS已经写了一个漂亮的数据访问接口。该企业库(应用程序块)的数据都漂亮合式花俏。

If you are going about it in the traditional manner (making your own queries), MS has already written a nice data access interface. The enterprise library (application blocks) for data have all of the nice well formed bells and whistles.

如果你不想费心编写查询,我建议你看的 LINQ2SQL linq2EF (preferred)。他们将大大简化您的编码。

If you dont want to bother with writing queries, I suggest you look at linq2Sql or linq2EF (preferred). They will greatly simplify your coding.

这篇关于如何处理在数据访问层连接(.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆