通过SQL身份验证连接时如何获取域名用户名 [英] How to Obtain Domain User Name when connecting via SQL Authentication

查看:116
本文介绍了通过SQL身份验证连接时如何获取域名用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个连接到SQL Server 2000(使用通用SQL登录名和SQL身份验证)的应用程序。我想通过触发器实现一些日志记录以跟踪数据更改。我不能使用 USER_NAME(),因为那样会返回通用帐户。

I have an application which connects to SQL Server 2000 (using a generic SQL Login and SQL Authentication). I would like to implement some logging via triggers to track data changes. I can't use USER_NAME() because that returns the generic account.

我已经通过 master..sysprocesses ,它似乎没有记录用户名(尽管它确实记录了计算机名称)。

I've poked through master..sysprocesses and it doesn't seem to record the username (although it does record the machine name).

有什么想法可以在SQL内访问用户名吗?

Any ideas how, within SQL, to gain access to the username?

(注意:是的,我可以通过应用程序将其作为变量传递...但是则意味着我必须推出该应用程序的新版本;我正在尝试在SQL中执行此操作,因此,如果可能的话,我可以避免这种情况。)

(Note: yes, I could pass it in as a variable via the application ... but that would mean I'd have to roll out a new version of the app; I'm trying to do this from within SQL, so I can avoid that, if possible.)

推荐答案

您不能。简单。 SQL Server完全不了解具有SQL登录

You can't. Simple. SQL Server has no knowledge of the end user with a SQL login at all

如果您使用代理(Web服务器等),则同样适用也:您不了解最终用户。我们使用参数/存储的proc来从Web服务器传递用户名。

The same applies if you use a proxy (web server etc) too: you don't know the end user. We use parameters/stored procs to pass in the username from the web server.

我建议您在客户端中设置CONTEXT_INFO,以保持该连接。

I would suggest that you set CONTEXT_INFO in the client which persists for that connection.

这篇关于通过SQL身份验证连接时如何获取域名用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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