如何保护池连接? [英] How to guard a pooled connection?

查看:111
本文介绍了如何保护池连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用一个sql服务器和连接由.net池。保护这种情况的好办法是:

In my app I work with a sql-server and connections are pooled by .net. What is a good practice to guard such a case:


池中的连接可能由于任何原因(网络,DBA终止会话,等)。在这些情况下,SQL Server会关闭连接,但SQL Client不知道任何内容。当物理关闭的连接重新分配时。打开连接时不会收到错误,这与打开非池连接不同。

Connections in the pool might be reset by any reason (network, DBA kill the session, etc). In those cases, SQL Server does close the connection, but SQL Client does not know anything about it. When a physically closed connection get re-assigned. You will not get error when you open the connection, this is different from opening a non-pooled connection. The error will arise when the first command is executed.

当然,这种情况是例外

推荐答案

尝试 / catch 是这种情况下的适当方法。您正在尝试处理基本上不受您控制的操作,这将导致应用程序在可识别的时机(检索数据时)出现错误。这正是尝试 catch 的用途。

try / catch is the appropriate approach in this case. You are trying to deal with an action that is basically not in your control, which would cause an error situation in your application at identifiable junctures (when retrieving data). This is exactly what try and catch are there for.

这篇关于如何保护池连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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