|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Saturday, February 13, 2010 12:45 AM
Points: 553,
Visits: 18
|
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 6:14 PM
Points: 32,891,
Visits: 26,763
|
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 6:14 PM
Points: 32,891,
Visits: 26,763
|
|
This is pretty cool... we have several complex, multi-step store procedures and some folks have put some pretty complex logging procedures in them just so they can query a table to see "how it's doing". With just a little forethought, you can add these simple lines to the proc and let the SysProcesses table take care of it… - SET @MyStatus = CAST('someprocname is at Step X' AS VARBINARY(128))
- SET CONTEXT_INFO = @MyStatus
With a bit more forethought, you could make a function that you pass the SPID to and it will automatically get the Context_Info from SysProcesses and decode it for readability. If you "word" it correctly, you could even put a timestamp in the Context_Info and have a view decode when the step started, how long the step has been running, the proc name (can save some space by passing the ID of the proc contained in sysobjects), etc. Then, just select from the view... use a WHERE for spid if you want. Combine that with the other available columns such as Host_Name, etc, and you have some pretty good info. Thanks, Yousef... nice tip.
--Jeff Moden "RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Tuesday, July 26, 2011 10:51 AM
Points: 6,
Visits: 7
|
|
Very Nice usage of CONTEXT_INFO. thanks for sharing. Have used CONTEXT_INFO for the Multilingual solution, where the clients call can come in for any language Data. Since the Connection pool is used to serve the data, before executing the SP we set the CONTEXT and within the SP, query the Sysprocesses to figure out the Language of the current SPID and serve the appropriate data.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Friday, March 22, 2013 6:48 AM
Points: 1,291,
Visits: 138
|
|
Regarding using this technique in an ASP environment, I would perform some additional testing. I'm not sure how Context_info applies when using connection pooling, but either way would appear to have problems. - This may destroy the ability to use connection pooling. Then each user will have there own connections, increasing resources on the both the db server and web (or app) server. Scalability and performance of your site will likely decrease.
- Or, if connection pooling still works when using context_info, then you will run the risk of having the Context_info reset on the connection, or being used by the wrong user. In an ASP app, there is no guarantee that you will get the same connection each time. And, other users will share the same connection.
Even still, thanks for the article, Yousef. Especially for the first intended purpose, this appears to the an elegant solution to your problem of restricting updates.
Mark
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, February 19, 2013 12:02 PM
Points: 169,
Visits: 101
|
|
| Does anyone know if the CONTEXT_INFO can be tracked in Profiler traces?
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 8:44 PM
Points: 104,
Visits: 720
|
|
| Wow, that's a pretty useful tip, something I never knew about. As you said in your article, I don't really need to use it right now but I'll definitely keep it in the back of my mind for the future. Thanks for sharing!
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, June 12, 2009 7:37 AM
Points: 125,
Visits: 115
|
|
Yep, its neat, and I wasn't aware of it. Does anyone on here know if there is a way (other than using this), to extract the calling stored procedure in a trigger? What would be nice if there was a way in 2000 or 2005 to be able to determine in a trigger the procedure name (or just if it was a batch) that invoked that trigger. Would be great for auditing purposes. Tim
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Friday, December 03, 2010 3:56 AM
Points: 124,
Visits: 91
|
|
Hello
It is really useful..
since long i was in search of read only tables.. I think this is one of the better way.
I followed all the steps that you have mentioned in your article, but i did not create any trigger.
as i dont want to use triggers.
what should be result according to you? Is there any other way without using triggers
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 7:49 AM
Points: 821,
Visits: 94
|
|
Intresting article. Thank you Yousef. I have one concern using this in SQL 2000. If you need to make sure you reset the Context_Info at the end of the procedure and an error occurs before it reaches that line in the stored procedure, won't it fail to execute the reset command?
|
|
|
|