Attempted to read or write protected memory. This is often an indication that other memory is corrupt ? RRS feed

  • Question

  • Hi All,

    I am working on app in which i am using ado.net for using  database.

    i am using timer for reading my database in every 40 seconds. Actually  if condition meets it will execute automatically for further queries.but i am getting below error randomly when timer initialize: 

    "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

    i found below solution on web,according to them if i follow i will rid out from this issue but still i am facing same issue.

    Tools menu ->Options -> Debugging -> General -> Uncheck this option "Suppress JIT optimization on module load"

    Please help me out.



    Saturday, March 9, 2013 2:04 PM

All replies

  • Hi Sumitk,

    Welcome to the MSDN forum.

    Do you mean you encountered the same issue after you tried the solution mentioned? I am not sure whether or not this solution works for you.

    Good day.

    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 11, 2013 8:11 AM
  • Hello Alexander,

    Yes i am still facing the same issue after tried the solution mentioned.



    Monday, March 11, 2013 10:17 AM
  • Hi, most of the times i get that error is because the underlying connection has been broken, i dont know your code, but try been explicit in opening and closing (and disposing) the database connection, if you can, avoid using some global connection object, try create - open - use - close - dispose connection to DB in each higher level action, if you have the connection pool configured this should be not a performance issue and should keep a good clean interaction with the database.

    Hope it helps.


    Tuesday, March 12, 2013 2:48 PM
  • Can you please post the code that you are using to execute your queries?

    Which timer are you using? (System.Threading.Timer or System.Timers.Timer?)

    Also, please be aware that using ADO.NET objects from multiple threads is not supported - it may be possible that the timer's "ticks" are overlapping, resulting in multiple instances of the timer's callback running at the same time.

    Daniel Paoliello [MSFT]
    ADO.Net Managed Providers and DataSet

    Wednesday, May 8, 2013 6:19 PM