问题标签 [set-context-info]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
84 浏览

tsql - How to store and extract number from binary field?

I have a procedure that is doing INSERT/DELETE operations over table and a trigger which is logging the changes in second table.

What I need is to pass the security user id that instantiated the procedure call to the trigger in order to record who user has made the changes.

It seems that the only way to do this is to use SET CONTEXT_INFO and CONTEXT_INFO().

The issue is, I am not able to extract the number(the user id). For example, the code below:

returns 0.

0 投票
0 回答
773 浏览

sql - 触发器中的 Context_info 值为空

我想在触发器开始执行时获得一些价值。但是,使用参数选项获取值在触发器中不可用。所以我决定将该特定值存储在一个变量中并将其传递给Context_info我的存储过程。

我在触发器中得到了这个值。但我仍然只得到空值。但是我通过将参数传递给存储过程手动尝试,它正确执行并且Context_info值也在该存储过程中正确显示。

但是当我在触发器中获得这个值时,它显示为 NULL。而且sys.dm_exec_sessions表中的context_info值也没有更新,但last_request_start_time正在last_request_end_time更新。

谁能指导我在哪里出错?

这是我的存储过程和触发器:

扳机

0 投票
0 回答
547 浏览

sql-server - 如何在触发器中获取值

我正在使用一个 DB 运行我的应用程序,但是在某些特定的表插入期间,我正在调用触发器,我需要从另一个 DB 获取一些值。以前我通过在触发器中硬编码特定的 DB 名称来做到这一点。我得到了正确的但现在我需要删除该数据库名称的依赖关系。所以我需要找到以另一种方式获取该特定值。任何人都可以帮我找到解决方案吗...

上一个触发器。

现在我做了一些改变,

我在一些 SP 中设置了 Context_info 值,如下所示。

现在的问题是,使用我注意到的 SQL Profiler,我可以正确获取此 SP 中的 clintID。但它没有正确地将这个 Context_info 保存在 sys.dm_exec_sessions 中。当我在 sql 中手动运行它时,

我 context_info 值已正确更新我不知道我错过了哪里。