Search code examples
c#compact-frameworksql-server-ce

sql ce native exception 0xc0000005


When i run my .net 3.5 cf application that reads some data from ms sql ce, sometimes i get an native exception with the following info:

ExceptionCode: 0xc0000005
ExceptionAddress : 0x44746e65 (variable)
Reading: 0x44746e64

at NativeMethods.GetKeyInfo(IntPtr pTx, String pwszBaseTable, IntPtr prgDbKeyInfo, Int32 cDbKeyInfo, IntPtr pError)

at SqlCeCommand.ExecuteReader(CommandBahavior behavior)

(... omitted for brevity)

at dadosGpsTableAdapter.GetDadosAEnviar()

My GetDadosAEnviar query is very simple:

SELECT        _id, Latitude, Longitude, Ignicao, Altitude, Velocidade,Direcao, Qualidade, Timestamp, Valido, Enviado, CondutorID
FROM            DadosGps
WHERE        (Enviado = 0)

and the code that calls this query is:

private bool SendRemainingData()
    {
        SetCurrentStatus("A Enviar historico");
        try
        {

            lock (lockObj)
            {
                DadosDataSet.DadosGpsDataTable dadosAEnviar = gpsAdapter.GetDadosEnviar();

                if (dadosAEnviar.Rows.Count > 0)
                {

                    foreach (DadosDataSet.DadosGpsRow amostra in dadosAEnviar.Rows)
                    {
                        bool resultado = webServicesGps.SendToServerGPSData(IMEI, amostra.Timestamp, amostra.Latitude, amostra.Longitude, Convert.ToDecimal(amostra.Altitude),
                            Convert.ToDecimal(amostra.Velocidade), Convert.ToDecimal(amostra.Direcao), new bool[] { amostra.Ignicao }, decimal.Zero, Convert.ToDecimal(amostra.Qualidade), "");

                        if (resultado)
                            gpsAdapter.RegistarEnvio(amostra._id);
                    }
                }
                dadosAEnviar.Dispose();
            }

(... omitted for brevity)

As you can see for the previous research i was indicated that it could be an sync issue between threads, so i use the lock statement with an

private static object lockObj=new object();

But the problem is when it calls the GetDadosAEnviar. What i can do to correct this behavior?

UPDATE

After more extensive debbuging i framed the code that causes the exception, it's on the auto-generated code vs creates:

this.Adapter.SelectCommand = this.CommandCollection[3];
        DadosDataSet.DadosGpsDataTable dataTable = new DadosDataSet.DadosGpsDataTable();
        //Next line "barfs" an native exception
        this.Adapter.Fill(dataTable);
        return dataTable;

Solution

  • SOLVED IT

    The error was caused by corruption of the sqlce native dll. By uninstalling and re-installing the sqlce everything worked. Better yet it is quicker, because of the time spent on optimizing the flow of code, instead of using stock VS boilerplate code