none
Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. RRS feed

  • Question

  • I tried to insert one table data to another table using storedprocedure. 80% records are inserted to the table but finally i got an error

    Unhandled Exception: System.AccessViolationException:

    Wednesday, April 27, 2016 11:53 AM

Answers

  • If the problem occurs in multi-threaded environment only, then the software (such as the database connector) probably does not support such scenario, or the objects are used incorrectly.

    As a possible workaround, make sure that no database objects (such as your db variable) are shared between threads. Create separate new objects within each thread.

    Friday, April 29, 2016 10:39 AM

All replies

  • I think it could be a problem of the database engine. Which one are you using (MSSQL, Access, MySQL, etc.)? Show some script and code details. If possible, try the same script manually using some tools.

    Wednesday, April 27, 2016 1:07 PM
  • I am using Informix Database

      for(int i=0; i<324933; i++) {
                        using (var dbCommand = db.GetStoredProcCommand("sp_test_para_add"))
                        {

                            db.AddInParameter(dbCommand, "name_New", DbType.String, i+"test");

                            db.ExecuteNonQuery(dbCommand);

                        }
                    }


    Thursday, April 28, 2016 4:44 AM
  • Hi Vishnu,

    >>"If possible, try the same script manually using some tools."

    I suggest you take the suggestion of @Viorel. Use while loop in sql to run same script on Informix.

    declare @num int
    set @num = 0;
    while @num < 324933
    begin
    	set @num = @num + 1
    	exec sp_test_para_add 
    end 

    In addition, you could use IfxCommand to do this work. Code below is for your reference.

    IfxCommand cmd = new IfxCommand("sp_test_para_add",conn);
    cmd.CommandType = CommandType.StoredProcedure; //from System.Data
    cmd.Parameters.Add("name_New",2+"test"); //many ways to create these
    try {
        cmd.ExecuteNonQuery();
    }
    catch (IfxException ifxe) {
        Console.WriteLine("Error "+ifxe.Message);
    }
    Best Regards,
    Li Wang

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 28, 2016 7:54 AM
    Moderator
  • Hi Li,

    I am using 'informix oledb' driver for connecting database.I need to get more than 300000 record form a table 'table1' and need to do some process for each record.Then i need to insert this each row to another table table2.But 90% data was successfully insert in 'table2' then i get an exception like this

    Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

       at System.Data.Common.UnsafeNativeMethods.IRowset.GetNextRows(IntPtr hChapter, IntPtr lRowsOffset, IntPtr cRows, IntPtr& pcRowsObtained, IntPtr& pprghRows)

       at System.Data.OleDb.OleDbDataReader.GetRowHandles()

       at System.Data.OleDb.OleDbDataReader.ReadRowset()

       at System.Data.OleDb.OleDbDataReader.Read()

       at PayrollDataInternal.PayDetailInserter.TransferPayDetails()

       at PayrollDataInternal.PayDetailInserter.InsertPayDetails(Object threadContext)

       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)

       at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()

       at System.Threading.ThreadPoolWorkQueue.Dispatch()


    Thursday, April 28, 2016 9:04 AM
  • If you are using threads, try without parallel threads yet.

    Also since the problem can be caused by some external issues (http://www-01.ibm.com/support/search.wss?q=ACCESSVIOLATIONEXCEPTION), make sure that you are using the updated software.

    Thursday, April 28, 2016 9:29 AM
  • Yes i am using parallel threads,But why the errors coming what was the reason for error

    Friday, April 29, 2016 10:30 AM
  • If the problem occurs in multi-threaded environment only, then the software (such as the database connector) probably does not support such scenario, or the objects are used incorrectly.

    As a possible workaround, make sure that no database objects (such as your db variable) are shared between threads. Create separate new objects within each thread.

    Friday, April 29, 2016 10:39 AM