0

I'm not sure if I'm asking the right question exactly, but if you know the answer then you'll probably understand what I'm asking.

I updated a stored proc and tested in dev w/ no problem. So then I updated the proc in production and it caused errors. Took me a bit to figure out what was going on because all I changed was a field in the select list from i.Price to Price = coalesce(r.Price, i.Price). Eventually I figured the only difference could be that r.Price is a decimal value whereas i.Price is a money value so the return type of the field had changed.

Normally that shouldn't matter for c# code. the DataReader value gets cast to decimal either way just fine. But all I had to do to fix the error was reset the app pool and then it worked. I believe I could have also updated my query to cast to a money type and that probably would have worked as well.

I know I've run into this kind of issue a few times before, enough to know there's some kind of caching going on under the hood in asp.net and/or the sql assemblies.

My question is, how can I get this cache to refresh without recycling the app pool. Or is that the only way?

BVernon
  • 3,205
  • 5
  • 28
  • 64

1 Answers1

1

Here what exactly happens when you deploy :

ASP.NET has a feature called shadow copying that enables assemblies that are used in an application domain to be updated without unloading the AppDomain. Normally, this is required because the Common Language Runtime (CLR) will lock the assemblies so you can’t just copy a new assembly over it. Shadow copying means that the original assembly is copied to a temporary location. The copied assembly is locked, and the original assembly can be updated with a new version.

What is assembly interning?

From :

From MSDN:

The ASP.NET shadow copy feature enables assemblies that are used in an application domain to be updated without unloading that AppDomain (necessary because the CLR locks assemblies that are being used). This is done by copying application assemblies to a separate location (either a default CLR-determined location or a user-specified one) and loading the assemblies from that location. This allows the original assembly to be updated while the shadow copy is locked. ASP.NET turns on this feature by default for Bin folder assemblies so that DLLs can continue to be updated while a site is up and running.

https://msdn.microsoft.com/en-us/magazine/hh882452.aspx

App Pool will be recycled automatically when below happens:

Any modifications in the Application’s BIN Directory

Making changes in any Configuration File/s, like Web.config or others ( if you have any specific config file in your application say in a directory called App_Config).

Making modifications in the Source code files in APP_CODE Directory. This maybe change in any Source code files, or adding or deleting files from this directory.

Making changes in the Global.asax file

Making Changes in the Machine.config file.

Making any modifications in the Web Application’s Root Directory. This means creating files/subdirectories on the fly can lead to application pool recycling.

Modifications for references of Web Services of App_WebReferences directory.

Modifying the Security Settings of any directory in the Root directory. (Like specifying read security rights for everyone or any other specific user or user group.)

For more details : Does any change in any file inside bin folder cause application recycle in ASP.NET web application?

Hany Habib
  • 1,377
  • 1
  • 10
  • 19
  • Hmm... upvote for the info but not sure if you get me. I am not deploying... just updating a stored proc via ssms. And obviously doing that does not recycle the app pool, nor do I want it to. However, because it's already called the stored proc that I've changed it keeps expecting a money value for price instead of decimal so I have to recycle app pool. I know c# doesn't care whether it's a decimal or money... treats both the same. But something cares... I want to know how to refresh that 'something' without recycling if possible. – BVernon May 30 '18 at 23:25
  • I think it's similar to when you're in SSMS and you lose your connection, but then get it back. The next query you run gives you an error but then ssms is smart enough to automatically try to reconnect and your next query works fine. Actually I guess that kind of answers my question... I could write code that attempts to close and open a new connection if there is a problem; well except it would be the same connection string which is pooled so I'd have to figure out how to really get it to open a new connection instead of returning the same pooled one. Or something like that. – BVernon May 30 '18 at 23:28
  • Oh, forgot to finish my thought: the point was that if ssms didn't automatically reconnect for you, then you would just keep getting the same error as is what happens in application that don't employ this logic. A little different than my scenario, but sort of similar in that I think I need to get a new connection to make it work again. – BVernon May 30 '18 at 23:30