2012-01-19 52 views
11

我用CONTEXT_INFO跳過觸發這樣:如何設置CONTEXT_INFO = NULL?

IF CONTEXT_INFO() = 0x676E6F7468692073656175746F6E RETURN 

,並在我的PROC:

IF CONTEXT_INFO() IS NOT NULL SET @CONTEXT_INFO = CONTEXT_INFO() -- to restore later 
SET CONTEXT_INFO 0x676E6F7468692073656175746F6E 

如何將其重新設置爲NULL,如果你需要的? SET CONTEXT_INFO = NULL確實不是工作。我錯過了明顯的東西嗎?

回答

19

只需使用

SET CONTEXT_INFO 0x /*Gets padded with zeros when cast to binary(128)*/ 

你不將它設置爲NULL。如果你看看

select context_info 
from sys.sysprocesses 

你會發現它不是NULL的任何連接。

+1

但是在它被定義之前它是空的:select context_info() – SQLMason

+0

+1用於提示sys.sysprocesses – SQLMason

+2

@DanAndrews - 如果它被清零'select context_info()'返回'NULL'。即'SET CONTEXT_INFO 0x; select context_info()' –