Internal Error: Cannot Access Shared Memory Region (XPe)


  • -Windows XP Embedded (Enhanced Write Filter ENABLED)
    -1GB RAM
    -.NET 4.0
    -Linq to SQL
    -Sql Server Compact 3.5 SP2
    -User account is Administrator with full privileges
    -SqlCe .sdf file is saved on a USB drive that is always connected

    I'm getting the exception in the subject line when using a SqlCe database in my C# application, and the other questions on the topic didn't seem to apply.  The user has full privileges to read/write to the file, and the file is not stored on a network drive.  This application is the only application that accesses the database, and it's not multithreaded.  Furthermore, most of the time accessing the database works just fine.  This problem seems to be intermittent, but when it does occur the application must be restarted because the error will just continue to occur.  Some users have also reported an "OutOfMemoryException" intermittently which I don't think is related to SqlCe access and I haven't been able to get more information on whether it's our application that's using up all of the system memory or another application on the system, but maybe low system memory is causing the Internal Error?

    To give some background on the application, it's using a SqlCe database that typically contains 1,000-5,000 records.  When the application is loaded, all of the data is loaded from the database and cached into memory.  On disk, the size of the database file has never been more than 1MB.  The caching was done because before we used a USB drive we were using a Compact Flash card and access was unacceptably slow.  When we switched to saving data onto a USB drive, the application wasn't changed.  The only time the database is accessed is on startup when the data is cached, and when any data is saved back to the database.  Any "reads" are just done from what's in memory.

    There's exactly 2 methods in the entire application that save data, pasted below.  In both cases, I'm using plain-text SQL queries instead of relying on Linq to SQL tracking because Linq to SQL was having trouble tracking changes through relationships so this was a workaround.

    public void AddRecord(Record newRecord)
                using (RecordDataClassesDataContext db = new RecordDataClassesDataContext (ConnectionString))
                    DataLoadOptions loadOptions = new DataLoadOptions();
                    loadOptions.LoadWith<Class1>(s => s.Property1);
                    loadOptions.LoadWith<Record>(r => r.Class1);
                    loadOptions.LoadWith<Record>(r => r.Class2);
                    loadOptions.LoadWith<Record>(r => r.Class3);
                    loadOptions.LoadWith<Class3>(t => t.Property2);
                    db.LoadOptions = loadOptions;
                    db.DeferredLoadingEnabled = false;
                    db.ExecuteCommand(@"INSERT INTO Records
                    foreach (long i in db.ExecuteQuery(typeof(long), "SELECT MAX(ID) FROM Records"))
                        newRecord.ID = i;
                    _recordBindingList = db.Records.GetNewBindingList();

    public void SaveRecord(Record updatedRecord) { if (updatedRecord.ID == 0) { AddRecord(updatedRecord); } else { using (RecordDataClassesDataContext db = new RecordDataClassesDataContext (ConnectionString)) { db.ExecuteCommand(@"UPDATE [Records] SET Field1 = {0}, Field2 = {1}, Field3 = {2}, Field4 = {3}, Field5 = {4}, Field6 = {5}, Field7 = {6}, Field8 = {7}, Field9 = {8} WHERE ID = {9}", updatedRecord.Property1, updatedRecord.Property2, updatedRecord.Property3, updatedRecord.Property4, updatedRecord.Property5, updatedRecord.Property6, updatedRecord.Property7, updatedRecord.Property8, updatedRecord.Property9, updatedRecord.ID); } } }

    Any help would be appreciated.  Thanks.

    Thursday, September 12, 2013 4:09 PM

All replies

  • I think it may be related to LINQ to SQL, try to rewrite the two statements to use ADO.NET only (SqlCeConnection, and SqlCeCommand) with parametereized SQL

    Please mark as answer, if this was it. Visit my SQL Server Compact blog

    Friday, September 13, 2013 7:04 AM