通过 SQL 身份验证连接时如何获取域用户名

发布于 2024-09-26 15:50:21 字数 315 浏览 1 评论 0原文

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

我浏览过 master..sysprocesses ,它似乎没有记录用户名(尽管它确实记录了机器名称)。

有什么想法如何在 SQL 中获取用户名的访问权限吗?

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

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.

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

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

(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.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雄赳赳气昂昂 2024-10-03 15:50:21

你不能。简单的。 SQL Server 完全不知道具有 SQL 登录名的最终用户。

如果您也使用代理(Web 服务器等),同样的情况也适用:您不知道最终用户。我们使用参数/存储过程从 Web 服务器传入用户名。

我建议您在客户端中设置 CONTEXT_INFO,该信息对于该连接持续存在。

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

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.

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

时间海 2024-10-03 15:50:21

您是否尝试过SYSTEM_USER

SELECT SYSTEM_USER

Have you tried SYSTEM_USER?

SELECT SYSTEM_USER
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文