检测不可用池SqlConnections [英] Detecting unusable pooled SqlConnections

查看:198
本文介绍了检测不可用池SqlConnections的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图设置一个SqlConnection与 sp_setapprole 我有时会收到以下错误在Windows事件日志...

When I attempt to set an application role on a SqlConnection with sp_setapprole I sometimes get the following error in the Windows event log...

的连接已断开,因为打开它随后承担了新的安全上下文,然后将主要试图重置其模拟的安全上下文的连接。不支持此方案。请参阅模拟概述联机丛书中。)

The connection has been dropped because the principal that opened it subsequently assumed a new security context, and then tried to reset the connection under its impersonated security context. This scenario is not supported. See "Impersonation Overview" in Books Online.)

...和匹配的异常被抛出在我的应用程序。

... and a matching exception is thrown in my application.

这些是连接池,并且曾经有一段时间,当连接池是不符合程序的角色 - 事实上,旧的建议来自微软是的禁用连接池(!),但引进的 sp_unsetapprole 的现在是(理论上)可能将其返回到池之前清除连接。

These are pooled connections, and there was a time when connection pooling was incompatible with app roles - in fact the old advice from Microsoft was to disable connection pooling (!!) but with the introduction of sp_unsetapprole it is now (in theory) possible to clean a connection before returning it to the pool.

我相信当(原因不明)sp_unsetapprole未连接上运行之前它被关闭并返回到连接池发生这些错误。 sp_approle然后就注定当从池中返回此连接失败。

I believe these errors occur when (for reasons unknown) sp_unsetapprole is not run on the connection before it is closed and returned to the connection pool. sp_approle is then doomed to fail when this connection is returned from the pool.

我可以捕获和处理这个异常,但我更preFER检测到即将发生的故障,避免了异常(和消息在事件日志)共有。

I can catch and handle this exception but I would much prefer to detect the impending failure and avoid the exception (and messages in the event log) altogether.

时有可能检测该问题,而不会导致该异常?

Is it possible to detect the problem without causing the exception?

想法或建议欢迎。

推荐答案

不,这是不可能的。

这篇关于检测不可用池SqlConnections的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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