none
Re: Native Exception Error - 0xc0000005 on SQL Server Mobile 2005 Repair

    Question

  • Hi,

    I got this access violation as I do a Repair on an SQL Server 2005 mobile edition database.

    The exception occurs only on a specific type of corruption of my database.

    The Exception information :

    ExceptionCode: 0xc0000005

    ExceptionAddress: 0x01669a48

    Reading: 0x00000014

    The log of the corruption is the following :

    Source : Storage Card\mydb.sdf
    Destination : \Storage Card\sql8000.tmp
    Repairing - verMajor: 3, verMinor: 0, verBuild: 5206, verPoint: 0
    Time - 2007-17-01 16:31:55.000
    Bad Checksum - idPage: 1031, tyPage: 3, iPage: 2
    Bad Checksum - idPage: 3828, tyPage: 4, iPage: 1
    Bad metadata - m_blobOwner
    Block page not found - pwszTable: __SysObjects, idPage: 205635
    Block page not found - pwszTable: __SysObjects, idPage: 242451
    Block page not found - pwszTable: __SysObjects, idPage: 197411
    Block page not found - pwszTable: __SysObjects, idPage: 197411
    Block page not found - pwszTable: __SysObjects, idPage: 234419
    Block page not found - pwszTable: __SysObjects, idPage: 242707
    Block page not found - pwszTable: __SysObjects, idPage: 197379
    Out-of-bounds index ordinal - pwszTable: MY_TABLE, pwszIndex: id_DateEnvoi, iIndex: 1

    DateEnvoi is a date field and it's probably not a good idea to use an index on but ....

    The access violation may come from my own log methods : I have to protect it from concurrent thread access.

    But it really seems to come from inside the SqlCeEngine.Repair method, because I don't have this problem on any other corruption type.

    Anyway, I get the same kind of exception when I try to use this method : GlobalMemoryStatus

    That's why I guess my problem is more due to missing locks on my log methods which could be called by different threads at the same time.

    If you have any suggestion let me know. I let you know what was my trouble when I solve it.

    Thanks a lot

    Wednesday, January 17, 2007 4:27 PM

Answers

  • SOLVED the GlobalMemoryStatus access violation !!!

    It may be already noticed by the .net compact framework dev team or I may again be wrong on what I think to solve but please take a moment to read this post.


    I wrote a small smart device program in C# for WinCE 5.0 plateform and tested it on my MC3000c50 Symbol device. The program just have a unique thread (the main) and do a unique unmanaged call to GlobalMemoryStatus and the same access violation always occurs ... 0xc0000005

    I got sample project named "HardwareDistributor" coming from MobileLineofBusinessSolutionAccelerator which works fine.
    Actually it took a quite long time to understand the access violation exception is due to the declaration of MEMORYSTATUS which the unique argument of GlobalMemoryStatus.

    I have to precise I use the .NET framework 2.0 SP1
    The good way to declare GlobalMemoryStatus's argument :
            public class MEMORYSTATUS
            {
                public uint dwLength;
                public uint dwMemoryLoad;
                public uint dwTotalPhys;
                public uint dwAvailPhys;
                public uint dwTotalPageFile;
                public uint dwAvailPageFile;
                public uint dwTotalVirtual;
                public uint dwAvailVirtual;
            }
    the bad one :
            public struct MEMORYSTATUS
            {
                public uint dwLength;
                public uint dwMemoryLoad;
                public uint dwTotalPhys;
                public uint dwAvailPhys;
                public uint dwTotalPageFile;
                public uint dwAvailPageFile;
                public uint dwTotalVirtual;
                public uint dwAvailVirtual;
            }

    Something is strange about the msdn sample here :
    ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxnetcf/html/15095a41-1588-4dcd-9fe0-6dae97bfaa62.htm
    http://msdn2.microsoft.com/en-us/library/ms172518.aspx
    Those both version (local & online) of the "How To Get Device Memory"  indicate MEMORYSTATUS should be a structure as the "HardwareDistributor" sample indicate a class.
    I know it's coming from the "NET Framework Developer's Guide" but the msdn search marks it as .NET compact framework topic.

    I can swear you a simple program verify this fact on my Win CE 5.0 device and Windows
    Mobile 5.0 Pocket PC emulator.
    Pass a struct to GlobalMemoryStatus throw an access violation exception.


    I don't precisely understand why and I would be very grateful if anyone could explain that to me.

    It makes me think ... : Is there a Win CE 5.0 Pocket PC Emulator (I don't have any install) ?

    The fact is if I run the "HardwareDistributor" sample on  the  Emulator and make a call at main

    I hope you understood all I tried to explain. Thanks for your attention.
    I still have to deal with SQL server 2005 mobile edition access violation on Repair. Probably due to the nature of the database corruption and far from what I pointed in this post.

    Best Reguards,

    P.S : I don't find how to set the "HardwareDistributor" project for a Win CE 5 device (the device is not listed in the "Device Tools->Device" option), could you just tell me how I do that ?
    Thursday, January 18, 2007 5:53 PM

All replies

  • Hey

    I've still not solved the problem ...

    I protected my log methods with some Mutex. The Logger class looks something like this :


    public static class Logger {
        private static StreamWriter logFile = null;
        private static Mutex logLocker = new Mutex();

        public static void writeToDebugLog(String message, Exception ex) {
            try {
                logLocker.WaitOne();
                // write log file stuff
                logFile = new StreamWriter("\Storage Card\debug_log.log", true);
                if(ex != null)
                {
                    logFile.WriteLine("[" + System.DateTime.Now.ToString() + "] : " + "EXCEPTION WAS CATCH !!!");
                    if(ex.GetType() != null)
                    logFile.WriteLine(" Type = [" + ex.GetType().ToString() + "]");
                    if(ex.Message != null)
                    logFile.WriteLine(" Message = [" + ex.Message + "]");
                    if(ex.StackTrace != null)
                    logFile.WriteLine(" StackTrace = [" + ex.StackTrace + "]");
                }
                logFile.WriteLine("[" + System.DateTime.Now.ToString() + "] : " + message);
            }
            finally
            {
                if (null != DebugLogFile) DebugLogFile.Close();
                try{
                    logLocker.ReleaseMutex();
                }
                catch (Exception) {
                    logLocker = new Mutex();
                }
            }
        }
    };

    if someone could tell me if the way I use the Mutex is the good one for this kind of work, I would be gratefull ?!

    The debug/trace stuff I've done since yesterday really show the access violation native exception occurs on the GlobalMemoryStatus call.
    The way I use this GlobalMemoryStatus is the way explained here :
    http://msdn2.microsoft.com/en-us/library/ms172518.aspx
    So I guess it's the same for the Repair call on the strange corrupted database which produce an access violation too after several minutes !

    So ... I really don't know what I can do to prevent my application from crashing on this kind of native exception ...

    Where can I find more information about this please ?

    One last question :
    It seems the native exception exit my application in a bad way. I mean my application process is still running and I don't manage to kill the process (in the way I try to kill it).

    I'd like to know if this appends because my exit process in the Main() is not well written, or is there something special to do to avoid that this kind of native exception quits my application so badly ?
    Thursday, January 18, 2007 10:59 AM
  • SOLVED the GlobalMemoryStatus access violation !!!

    It may be already noticed by the .net compact framework dev team or I may again be wrong on what I think to solve but please take a moment to read this post.


    I wrote a small smart device program in C# for WinCE 5.0 plateform and tested it on my MC3000c50 Symbol device. The program just have a unique thread (the main) and do a unique unmanaged call to GlobalMemoryStatus and the same access violation always occurs ... 0xc0000005

    I got sample project named "HardwareDistributor" coming from MobileLineofBusinessSolutionAccelerator which works fine.
    Actually it took a quite long time to understand the access violation exception is due to the declaration of MEMORYSTATUS which the unique argument of GlobalMemoryStatus.

    I have to precise I use the .NET framework 2.0 SP1
    The good way to declare GlobalMemoryStatus's argument :
            public class MEMORYSTATUS
            {
                public uint dwLength;
                public uint dwMemoryLoad;
                public uint dwTotalPhys;
                public uint dwAvailPhys;
                public uint dwTotalPageFile;
                public uint dwAvailPageFile;
                public uint dwTotalVirtual;
                public uint dwAvailVirtual;
            }
    the bad one :
            public struct MEMORYSTATUS
            {
                public uint dwLength;
                public uint dwMemoryLoad;
                public uint dwTotalPhys;
                public uint dwAvailPhys;
                public uint dwTotalPageFile;
                public uint dwAvailPageFile;
                public uint dwTotalVirtual;
                public uint dwAvailVirtual;
            }

    Something is strange about the msdn sample here :
    ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxnetcf/html/15095a41-1588-4dcd-9fe0-6dae97bfaa62.htm
    http://msdn2.microsoft.com/en-us/library/ms172518.aspx
    Those both version (local & online) of the "How To Get Device Memory"  indicate MEMORYSTATUS should be a structure as the "HardwareDistributor" sample indicate a class.
    I know it's coming from the "NET Framework Developer's Guide" but the msdn search marks it as .NET compact framework topic.

    I can swear you a simple program verify this fact on my Win CE 5.0 device and Windows
    Mobile 5.0 Pocket PC emulator.
    Pass a struct to GlobalMemoryStatus throw an access violation exception.


    I don't precisely understand why and I would be very grateful if anyone could explain that to me.

    It makes me think ... : Is there a Win CE 5.0 Pocket PC Emulator (I don't have any install) ?

    The fact is if I run the "HardwareDistributor" sample on  the  Emulator and make a call at main

    I hope you understood all I tried to explain. Thanks for your attention.
    I still have to deal with SQL server 2005 mobile edition access violation on Repair. Probably due to the nature of the database corruption and far from what I pointed in this post.

    Best Reguards,

    P.S : I don't find how to set the "HardwareDistributor" project for a Win CE 5 device (the device is not listed in the "Device Tools->Device" option), could you just tell me how I do that ?
    Thursday, January 18, 2007 5:53 PM