如何获取 CLR 触发器中当前执行命令的 sql server 用户名?

发布于 2024-07-25 22:25:29 字数 130 浏览 1 评论 0原文

我知道 SqlContext.WindowsIdentity 返回正在执行命令的当前用户(在 CLR 触发器中),但是,这仅适用于经过 Windows 身份验证的用户。 如果是 sql server 用户,如何获取用户名? 任何帮助表示赞赏。

I know that SqlContext.WindowsIdentity returns the current user that is executing the command (in a CLR trigger), however, this only works for windows authenticated users. How do I get the username if it's a sql server user instead? Any help is appreciated.

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

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

发布评论

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

评论(3

世界等同你 2024-08-01 22:25:29

尝试在 SQL Server 中使用 SUSER_NAME() 函数。 这将返回当前用户。

Try using SUSER_NAME() function in SQL server. This will return the current user.

人生百味 2024-08-01 22:25:29

尝试使用 SYSTEM_USER。

SELECT SYSTEM_USER

Try using SYSTEM_USER.

SELECT SYSTEM_USER
请帮我爱他 2024-08-01 22:25:29

您可以使用当前连接的上下文并从连接对象中获取所需的所有内容。

像这样(在 C# 中):

SqlConnection connection = new SqlConnection("context connection=true");

You can use context of the current connection and get all you need from the connection object.

Like this (in C#):

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