Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with compact sql in background thread creates memory problems

Status
Not open for further replies.

dseaver

IS-IT--Management
Jul 13, 2006
467
I am working creating a program in VS2005 which creates, populates and queries a Sql Server Compact Edition database. I am threading the sql queries and excel and Pdf generation so that the GUI doesn't lock up. I was debugging the functions for querying and report generation without threading the methods, but as soon as I moved the methods to a background worker, I started getting the following exception: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

When I populate the DB in a thread it works fine, but when I switch to a different thread and try to execute the exception when I run the fill method ("resultAdapt.Fill(resultTable);"). The methods worked fine when it wasn't threaded.

here is a partial stack trace
Code:
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at System.Data.SqlServerCe.NativeMethods.Move(IntPtr pSeCursor, DIRECTION direction, IntPtr pError)
   at System.Data.SqlServerCe.SqlCeDataReader.Move(IntPtr pSeCursor, DIRECTION direction)
   at System.Data.SqlServerCe.SqlCeDataReader.Move(DIRECTION direction)
   at System.Data.SqlServerCe.SqlCeDataReader.Read()
   at System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping)
   at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
   at System.Data.Common.DataAdapter.Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
   at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)

I tried googling the exception and found nothing that would fix the problem
 
I found the problem, I was still calling the method in the main thread and then calling it in the background thread, causing a collision.
 
Figured it was something along those lines. Glad you got it sorted :)

[small]----signature below----[/small]
Majority rule don't work in mental institutions

My Crummy Web Page
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top