可以从内置的数据库连接池无状态的WCF服务的好处? [英] Can a stateless WCF service benefit from built-in database connection pooling?

查看:423
本文介绍了可以从内置的数据库连接池无状态的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服务的好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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