Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat are best practices for using thread local storage in .NET?
    primarykey
    data
    text
    <p>I have a requirement in my application that I think can be met by using thread local storage, but I'm wondering if it's one of those things that's best to avoid.</p> <p>I have read a few articles on the subject:</p> <p><a href="http://www.dotnetcoders.com/web/Articles/ShowArticle.aspx?article=58" rel="nofollow noreferrer">http://www.dotnetcoders.com/web/Articles/ShowArticle.aspx?article=58</a></p> <p><a href="http://msdn.microsoft.com/en-us/library/system.threadstaticattribute(vs.80).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/system.threadstaticattribute(vs.80).aspx</a></p> <p>I know <em>how</em> to use it, I'm just wondering if I <em>should</em> use it.</p> <p>Any advice, gotchas to be aware of?</p> <p><strong>[Edit]</strong></p> <p>Here's the use case: </p> <p>I funnel all data access through a few methods that do a lot of logging about each query. One thing I log is a complete dump of the command text with commands filled in so that I can simply copy-paste from my trace logs directly into Sql Management Studio.</p> <p>Way up in global.asax in my web apps I send email to admins with as much information as I can when I get an unhandled exception. I want to put that sql command dump text into this email when I get a SqlException, which will save me the time of digging through trace logs when a page blows up because of a query.</p> <p>I don't want to change the method signatures of my data access classes just so I can pass some reference all the way down the stack, just to get it out when I get an exception. I was thinking maybe TLS would be a good place to put something like "lastsqlcommand", but that's not looking like a viable solution.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload