Microsoft Developer Network > Forums Home > BizTalk Server Forums > BizTalk Server General > How to not let BizTalk Help Class Code cache a customize config file?
Ask a questionAsk a question
 

AnswerHow to not let BizTalk Help Class Code cache a customize config file?

  • Thursday, October 29, 2009 4:22 AMXiao Han Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have a BizTalk 2006 R2 solution. It uses some C# code in the help class to do some calculation.

    At some stage of the data processing, the C# code reads a xml config file from a fix directory and also overwrites some value in that config file.

    But I found that after I manually changed some value in the config file, I have to restart BizTalk host instance to clean the cache of the config file.

    I am wondering is there anyway to not let the config file be cached by BizTalk Help Class?

    Also if I let BizTalk Help Class automatically overwrites the value in the config file before it is being read, will BizTalk still keep the cache of the config file?

    Thank you.

Answers

  • Thursday, October 29, 2009 9:25 AMAbhijit Mahato Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    In my openion, storing config values in SSO database would be the better option.

    There is a very good article "Where do I store my custom configuration for a BizTalk solution". I would suggest you to please go thru the below link once........ You will have a better understanding.... Where you should store your config values?

    http://geekswithblogs.net/michaelstephenson/archive/2008/05/25/122381.aspx


    Regards,
    Abhijit


    Abhijit Mahato Please "Mark as Answer" if Post has Answered the Question
  • Wednesday, November 04, 2009 9:41 AMWen-Jun ZhangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Xiao,

    You original issue isn't a typical 'caching' case. The essential is that appSettings simply doesn't have the ability to notice file change notifications on the config file. In other words, dynamically changing .config and reloading isn't supported. An app restarting should be required.

    So as you already tried, using database to store the config should be the correct approach for you.

    Thanks.
    Sincerely WenJun Zhang - MSFT Microsoft Online Community Support Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

All Replies

  • Thursday, October 29, 2009 8:07 AMRandal van SplunterenModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    This basically depens very much on how you read, write and cache the config file. Since you're using C# code you have many possibilities to implement this.

    There must be a way to refresh the cache after writing to the config file. Can you post the relevant parts of your code?


    HTH, Randal van Splunteren - http://biztalkmessages.vansplunteren.net - Please mark as answered if this answers your question.
  • Thursday, October 29, 2009 9:03 AMXiao Han Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I use a Config.cs file in the help class to map all the configuration tag in the xml config file at the fixed directory.

    I access the value by doing something like if (Config.HasProcessed == "True") to detect the value

    Each Tag defined in the xml config file has a local variable like a key in the Config.cs file. And I use the Get and Set method to read and write the value.

    I am thinking if I move the config setting to a database table, would this solve the problem I have?

    Thank you.
  • Thursday, October 29, 2009 9:25 AMAbhijit Mahato Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    In my openion, storing config values in SSO database would be the better option.

    There is a very good article "Where do I store my custom configuration for a BizTalk solution". I would suggest you to please go thru the below link once........ You will have a better understanding.... Where you should store your config values?

    http://geekswithblogs.net/michaelstephenson/archive/2008/05/25/122381.aspx


    Regards,
    Abhijit


    Abhijit Mahato Please "Mark as Answer" if Post has Answered the Question
  • Thursday, October 29, 2009 9:35 AMTim Dhaeyer Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    Do you load your file every time? Or only once?
    Because if you would only load this once in say a static variable, then you have a caching problem.

    Kind regards
    Tim
  • Thursday, October 29, 2009 11:33 AMXiao Han Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    Do you load your file every time? Or only once?
    Because if you would only load this once in say a static variable, then you have a caching problem.

    Kind regards
    Tim
    As the condition statement I show above, The Tag <HasProcessed> value e.g. "True" in the config file will be read every time BizTalk application receive a file to process. After some condition, the value would be changed to "False" by the BizTalk Application. For Testing, I manually change the value from true to false, but BizTalk keeps caching the value "True".

    Every time after the value in the config file is read, a local variable is created to keep the value during the process.
  • Thursday, October 29, 2009 11:35 AMXiao Han Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    In my openion, storing config values in SSO database would be the better option.

    There is a very good article "Where do I store my custom configuration for a BizTalk solution". I would suggest you to please go thru the below link once........ You will have a better understanding.... Where you should store your config values?

    http://geekswithblogs.net/michaelstephenson/archive/2008/05/25/122381.aspx


    Regards,
    Abhijit


    Abhijit Mahato Please "Mark as Answer" if Post has Answered the Question
    Yeah, I found that post before I started this question in the forum.

    Store the value in the SSO database, does that mean any database such as the database which is for this BizTalk application? Or it has to be the BizTalk application?

    If I store the value in a database table, would this solve the caching issue?
  • Thursday, October 29, 2009 11:51 AMAbhijit Mahato Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    If I store the value in a database table, would this solve the caching issue?
    Yes.. If you store the value in a database table, you would not face the caching issue.


    Regards,
    Abhijit

    Abhijit Mahato Please "Mark as Answer" if Post has Answered the Question
  • Thursday, October 29, 2009 1:31 PMGreg.ForsytheMVP, AnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Using a database to store config will only solve the caching issue by not caching. So every reference to the config value will require a database request for the config value.  This replaces the cache concurrency issue with a potential performance issue.
    If performance is not a problem then the database solution is fine, otherwise you will need to investigate a smarter caching mechanism e.g. NCache or the Enterprise Library Caching Block. I have used a lightweight caching mechanism that creates a FileWatcher on the config file. If the file every changes it reloads the cache. 
  • Thursday, October 29, 2009 9:27 PMXiao Han Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I think the performance is not a problem for this BizTalk application.

    It only reads one file to process everyday, and this configuration value only reads once for each file.

    I am wondering in Visual Studio 2005, the Help Class project setting, is there anything could stop .Net caching?
  • Friday, October 30, 2009 2:00 AMXiao Han Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I just tried that, it works.

    But I don't understand, in the post Where do I store my custom configuration for a BizTalk solution , it also mentioned customized configuration file, so I guess it should work. I read the code, it is pretty much the same idea. So anyway knows why the one in the post it works, but the one I have not?

    Thank you.

  • Friday, October 30, 2009 6:20 AMTim Dhaeyer Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Xiao,

    If you want to use a .config file in a BizTalk solution. You have to use the BTSNTSvc.exe.config
    You can store your values in there. Just don't forget this when you do the installation on a different server.

    Kind regards
    Tim
  • Wednesday, November 04, 2009 9:41 AMWen-Jun ZhangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Xiao,

    You original issue isn't a typical 'caching' case. The essential is that appSettings simply doesn't have the ability to notice file change notifications on the config file. In other words, dynamically changing .config and reloading isn't supported. An app restarting should be required.

    So as you already tried, using database to store the config should be the correct approach for you.

    Thanks.
    Sincerely WenJun Zhang - MSFT Microsoft Online Community Support Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Wednesday, November 04, 2009 11:32 AMGreg.ForsytheMVP, AnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    In case you ever need to cache the results from the database or a config file, here is some sample code :)
    Allows for refresh on a timer and/or a file change event 

    http://cid-4e9c10425c5f8e8f.skydrive.live.com/self.aspx/Public/SimpleCache.zip
  • Wednesday, November 04, 2009 4:49 PMlindabztk Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    An alternative way of using database is to store the value in a seperate config file (not the BTSBTSVC.exe.config), it doesn't cache at all -- which avoids caching issue. It's almost the same idea of the database approach except that you don't have to deal with database. What I am not sure about is whether file locking could be an issue, it depends on the read/write frequency and concurrency.

    Note: A seperate config file can be access by ConfigurationManager.OpenMappedExeConfiguration.


    Linda