4

I've got an older application that is connecting via ODBC to my database server. I want to discover what the Application Name is inside a stored procedure. I'm not able to set the Application Name (or the ProgramName value in xp_who2) at login due to the ODBC ware not supporting it. Is it possible to set that value after login via some "set" command?

I understand there are other ways around this (like calling my stored procedure with the application name) but I'm hoping to avoid that as it would require more than one coding change, and rather do something for this session just after login.

1 Answer 1

5

What about using SET CONTEXT_INFO? It takes a varbinary(128) value, but you can easily cast that to/from varchar or whatever is appropriate. Read it back from sysprocesses.

http://msdn.microsoft.com/en-us/library/aa259199(v=sql.80).aspx

3
  • Interestingly enough, that is exactly what another guy in my shop told me after I posted this. Thanks! Commented Mar 30, 2012 at 17:13
  • The only caution is that each connection only has one CONTEXT_INFO, so make sure you don't accidentally stomp on it with some other data later. But it's pretty handy if you want to persist, for example, the application name, the user that's logged in to the web application, etc. Then you have access to this information within triggers, which is nice.
    – db2
    Commented Mar 30, 2012 at 17:45
  • Good caution. I will create some sp to write to and read the value from it, thereby preventing the overwrite scenario. I'm hoping there might be something out in the blogsphere too for this, but perhaps not. Commented Mar 30, 2012 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.