Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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

share|improve this answer
    
Interestingly enough, that is exactly what another guy in my shop told me after I posted this. Thanks! –  Nick DeVore Mar 30 '12 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 Mar 30 '12 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. –  Nick DeVore Mar 30 '12 at 21:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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