简体   繁体   中英

ExceptionCode: 0xc0000005 using SQLCE when ExecuteReader() statement executes

I have this code:

 string TmpMakat, TmpIsShakil, TmpDes;
        SqlCeDataReader read;
        public bool LOOK()
        {
            try
            {
                TmpMakat = "";
                TmpIsShakil = "";
                TmpDes = "";
                Cmd.CommandType = CommandType.TableDirect;
                Cmd.CommandText = "Items";
                Cmd.IndexName = "A";
                Cmd.SetRange(DbRangeOptions.Match, new object[] { txtMakat.Text }, null);
                try
                {
                    read = Cmd.ExecuteReader(); // <--- This is the Error
                }
                catch
                {
                    MessageBox.Show("Error");
                    return false;
                }
                while (read.Read())
                {
                    TmpMakat = read[0].ToString();
                    TmpIsShakil = read[1].ToString();
                    TmpDes = read[2].ToString();
                }
                read.Dispose();
                if (TmpMakat == "")
                {
                    TmpMakat = "";
                    TmpIsShakil = "";
                    TmpDes = "";
                    lblDes.Text = "";
                    lblQty.Text = "";
                    return false;
                }
                else
                {
                    IsShakil = (TmpIsShakil == "1") ? true : false;
                    lblQty.Text = (IsShakil == true) ? "B" : "A";
                    lblDes.Text = TmpDes;
                    return true;
                }
            }
            catch
            {
                return false;
            }
        }

but if there is any error - it never goes into the catch

I get this error sometime:

Error
A native exception has occurred in
myProg.exe.
Select Quit and then restart this program, or select Details
for more information.

and when I press for more Details I see this:

Error
ExceptionCode: 0xc0000005
EceptionAddress: 0x41efaf7c
Reading: 0x00000000
Faulting module: sqlcese35.dll
Offset: 0x0005af7c

ExceptionCode: 0xc0000005

That's a nasty one, AccessViolationException in .NET speak. Clearly SQL Compact is crashing, it is probably doing so in a worker thread or your catch clause would have caught it. Diagnosing this is going to be difficult but start by mistrusting the database file content, it might be corrupted. Consider an out-of-memory problem, it is bombing on a null pointer dereference. Look for updates from Microsoft.

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.

The error happens in native code (SQL CE), so

either the .NET compact framework is unable to catch this kind of error (don't know, would be strange, but hard to ignore)

or the error happens in the first line, which is outside the try/catch block.

As you are calling a CreateCommand method, which we can assume, calls down to SQL CE, the 2nd possibility is more likely.

Can you put the assignment in the try/catch block ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM