问题
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;
回答1:
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
回答2:
Is the SqlCeConnection being used at the same time on another thread?
If that is the case, you may need a lock there too. To test, make a new connection (temporarily) and see if it fixes it.
回答3:
I had exactly the same error and was pulling my hair out with frustration, not getting anywhere. I references the SQL CE dlls directly and copied them all to the device during deploy, so after I read the above solution I tried to remove all the files and redeploy from scratch. That also did not work. In the end I installed SQL Server CE 3.5 SP2 directly on to the device with the CAB file found in
C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Devices\wce500\armv4i\sqlce.wce5.armv4i.cab
(ARMv4 in my case, your's may vary). After installing this to the device everything ran fine.
来源:https://stackoverflow.com/questions/5154488/sql-ce-native-exception-0xc0000005