如何分辨谁是登录到SQL Server谁是、SQL、Server

由网友(我只是喜歡你)分享简介:我设计一个应用程序,我在寻找说谁是当前登录到SQL服务器的最佳方式。我将使用内置到SSMS活动监视器,它显示了访问服务器的所有进程的列表 - 很酷I am designing an application and I'm looking for the best way to tell who is currentl...

我设计一个应用程序,我在寻找说谁是当前登录到SQL服务器的最佳方式。我将使用内置到SSMS活动监视器,它显示了访问服务器的所有进程的列表 - 很酷

I am designing an application and I'm looking for the best way to tell who is currently logged into SQL server. I will use the Activity Monitor built into SSMS, which shows a list of all processes accessing the server - very cool.

不过,如果在我的.NET code,它使用一个单独的连接每一个我访问数据库的话,我将如何能够告诉当前登录的是谁时?如果用户只盯着屏幕,而不是从数据库的那一刻检索数据,那么他们就不会显示正确的?

However, if in my .NET code it uses a separate connection each time I access the database then how will I be able to tell who is currently logged in? If a user is just looking at a screen and not retrieving data from the database at that moment then they wouldn't show up correct?

推荐答案

也许是,也许不是。你是很正确,被记录到应用程序中不需要用户登录到数据库中 - 事实上,这个概念是不存在的。活动Montitor(和,有效,sp_who2)将只显示活动连接 - 积极利用这些连接

Maybe, maybe not. You're correct that being logged into your application does not require a user to be logged into the database - in fact, that concept doesn't really exist. Activity Montitor (and, usefully, sp_who2) will show only active connections - those connections actively in use.

如果您使用连接池那画面变化(汇集= true时,我相信,在您的连接字符串)。做到这一点,和一个封闭的客户端连接将保持活跃,你会看到在监视器连接。 This文章有一些细节上。

That picture changes if you use pooled connections ("Pooled=true", I believe, in your connection string). Do that, and a "closed" client connection will remain active, and you'll see that connection in the monitor. This article has some more detail on that.

如果我是你,虽然,我最好的建筑师,不依赖于连接池用不同的方式来追踪活跃用户之一。

If I were you, though, I'd architect a different way to track active users, one that doesn't rely on pooled connections.

阅读全文

相关推荐

最新文章