可以从内置的数据库连接池无状态的WCF服务的好处?

编程入门 行业动态 更新时间:2024-10-27 10:34:17
本文介绍了可以从内置的数据库连接池无状态的WCF服务的好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

据我了解,访问一个(正的SQL Server),数据库典型的.NET应用程序没有做什么特别的事,以便从连接池获益。即使一个应用程序反复打开和关闭数据库连接,他们得到的框架汇集(假设的东西,如凭证不从呼叫更改呼叫)。

I understand that a typical .NET application that accesses a(n SQL Server) database doesn't have to do anything in particular in order to benefit from the connection pooling. Even if an application repeatedly opens and closes database connections, they do get pooled by the framework (assuming that things such as credentials do not change from call to call).

我的使用场景似乎有点不同。当我的服务被实例化时,它会打开一个数据库连接一次,做了一些工作,关闭连接并返回结果。然后它被拆掉了WCF和下一个来电创建服务的新实例。

My usage scenario seems to be a bit different. When my service gets instantiated, it opens a database connection once, does some work, closes the connection and returns the result. Then it gets torn down by the WCF, and the next incoming call creates a new instance of the service.

换句话说,我的服务得到每个客户端调用实例,如[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)。该服务可访问的SQL Server 2008数据库。我使用的是.NET Framework 3.5 SP1中。

In other words, my service gets instantiated per client call, as in [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]. The service accesses an SQL Server 2008 database. I'm using .NET framework 3.5 SP1.

是否连接池仍然工作在这种情况下,或者我需要推出自己的连接池在一个单身的形式或通过其他方式(IInstanceContextProvider?)。我宁愿避免重新发明轮子,如果可能的话。

Does the connection pooling still work in this scenario, or I need to roll my own connection pool in form of a singleton or by some other means (IInstanceContextProvider?). I would rather avoid reinventing the wheel, if possible.

推荐答案

这是访问(正的SQL Server),数据库没有做什么特别的事,以便从连接池获益典型WCF应用程序。即使一个应用程序反复打开和关闭数据库连接,他们得到的框架汇集(假设的东西,如凭证不从呼叫更改呼叫)。

Typical WCF application that accesses a(n SQL Server) database doesn't have to do anything in particular in order to benefit from the connection pooling. Even if an application repeatedly opens and closes database connections, they do get pooled by the framework (assuming that things such as credentials do not change from call to call).

服务实例化模型创建和眼泪就下来了你的类,而不是一个完整的应用程序域的一个实例。该SqlClient连接池是每的AppDomain ,所以你会得到你的免费午餐。

The service instancing model creates and tears down an instance of your class, not an entire appdomain. The SqlClient connection pool is per AppDomain, so you'll get your free lunch.

更多推荐

可以从内置的数据库连接池无状态的WCF服务的好处?

本文发布于:2023-11-09 03:16:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571248.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:好处   状态   数据库   连接池   WCF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!