从 T-SQL 存储过程获取应用程序可执行文件名称

发布于 2024-07-21 18:05:47 字数 146 浏览 4 评论 0原文

从 SQL Server 中的存储过程中,是否可以获取拥有该连接的可执行文件(即 MyApp.exe)的名称? 我知道有 APP_NAME(),但它似乎只返回传递到连接字符串中“应用程序名称”参数的任何字符串。

如果可以的话,怎样才能做到呢? 谢谢。

From a stored procedure in SQL Server, is it possible to get the name of the executable (ie MyApp.exe) that owns the connection? I know there is APP_NAME(), but that appears to just return whatever string was passed into the 'Application Name' parameter in the connection string.

If this is possible, how can it be done? Thanks.

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

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

发布评论

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

评论(6

恋竹姑娘 2024-07-28 18:05:47

您可以从连接字符串中获取计算机和信息,但基本上就是这样。

通过监控和其他措施,您可以确保开发人员始终在其连接字符串中使用应用程序名称。 例如,您可以记录不是已批准的应用程序名称的情况,或者使用探查器来监视事物。

You can get the computer and the information from the connection string, but that's basically it.

Through monitoring and other measures you can ensure that developers always use Application Name in their connection strings. For instance, you can log cases where it's not an approved applciation name, or use the profiler to watch for things.

夕色琉璃 2024-07-28 18:05:47

不幸的是,我不知道任何这样的事情 - 请记住,连接很可能来自完全不同的机器。

也许您可以设计安全性,以便不同的应用程序使用不同的用户名来访问数据库。 查找当前用户很容易。

Unfortunately I'm not aware of any such thing -- remember that the connection is coming from an entirely different machine most likely.

Perhaps you can design you security so that different apps are using different user names to access the database. Finding the current user is easy.

扛起拖把扫天下 2024-07-28 18:05:47

除非您修改存储过程以传递应用程序名称,否则您将只能使用 APP_NAME() 的结果。 希望开发人员在其中放置有意义的值,而不仅仅是接受默认值,默认值通常表示用于构建应用程序的开发工具。

希望这有帮助,

比尔

Unless you modify your stored procedure to pass the app name, you're stuck with the results of APP_NAME(). Hopefully, developers are placing meaningful values in there rather than just accepting the default value which is generally an indication of the development tool used to build the app.

Hope this helps,

Bill

始于初秋 2024-07-28 18:05:47

我意识到这不正是您正在寻找的。 但是您可以使用 DBCC INPUTBUFFER 确定调用堆栈的一部分。 如果您将这样的逻辑放入 storeprodedure 中并将其记录在某处,您可能会获得有关调用者的一些信息。

            CREATE TABLE #dbc
                (
                  EventType VARCHAR(15),
                  Parameters INT,
                  EventInfo VARCHAR(255)
                )
              DECLARE @execStr VARCHAR(500)
              SET @ExecStr = 'DBCC INPUTBUFFER(' + STR(@@SPID) + ')'



              INSERT    INTO #dbc
                        EXEC ( @execStr
                            )

              SELECT    *
              FROM      #dbc

I realize this isn't exactly what you are looking for. But you can determine a bit of the call stack by using DBCC INPUTBUFFER. If you put logic like this in inside the storeprodedure and log it somewhere you might get some info about the caller.

            CREATE TABLE #dbc
                (
                  EventType VARCHAR(15),
                  Parameters INT,
                  EventInfo VARCHAR(255)
                )
              DECLARE @execStr VARCHAR(500)
              SET @ExecStr = 'DBCC INPUTBUFFER(' + STR(@@SPID) + ')'



              INSERT    INTO #dbc
                        EXEC ( @execStr
                            )

              SELECT    *
              FROM      #dbc
入画浅相思 2024-07-28 18:05:47

Oracle 可以为您提供 exe 的名称,但 SQL Server 不能 - 不同的体系结构。

Oracle can give you the name of the exe, but SQL Server can't - different architecture.

私野 2024-07-28 18:05:47

您还可以获取客户端计算机上进程的 ID,因此如果您有某种神奇的方法将其映射到进程名称,那么您就可以做到这一点。

You can also get the ID of the process on the client machine, so if you had some magical way of mapping that to a process name then you could do it.

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