I’ve come across some code that has a singleton which creates / reuses a static instance of the MSDAAB Database object. Is the Database object threadsafe after creation? I couldn’t find anything one way or the other in the MSDAAB docs.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Despite this answer, I think the formal answer is no.
The reason why I say that is that
Databasecaches stored procedure parameters in an instance variable calledparameterCache.Items are added to the cache and the cache can also be cleared using the
ClearParameterCache()method without first obtaining a lock on theparameterCache.If
ClearParameterCache()is called, then it is possible to hit situations where one thread thinks there is an item in the cache then another thread clears the cache and when the first thread goes to retrieve the item it has been removed and an exception is thrown.The good news is that if
ClearParameterCache()is never called then the worst I would expect is that initially the parameters could be be derived multiple times and added to the cache multiple times (by different threads). I haven’t tested it but it looks like it should still work (although it is inefficient).So, practically, as long as you don’t call
ClearParameterCache()I think you should be OK.