KeyNotFoundException:SQLCE数据库异常

时间:2009-09-07 13:34:17

标签: c# compact-framework sql-server-ce

我在C#中使用dataSet。我直接计算了物品的数量 SQL CE数据库,所以我知道我在数据库中有多少项。数据库中没有删除。

我得到以下无法解释的异常:

System.Data.SqlServerCe.dll

中出现'System.Data.SqlServerCe.SqlCeException'类型的第一次机会异常

mscorlib.dll KeyNotFoundException中出现'System.Collections.Generic.KeyNotFoundException'类型的第一次机会异常

这表明通信与SQL CE数据库锁定的位置。

有谁知道是什么原因造成这种情况以及如何解决这个问题?

我在网上搜索过,但我没有任何解决方案: - (

        // List to be created
        List<TableDat> result = null;
        lock (_sqlcn)
        {
            // Assumes that connection is a valid SqlConnection object.
            SqlCeDataAdapter adapter = new SqlCeDataAdapter(orderSQL, _sqlcn);
            try
            {
                // DataSet that will be returned.
                System.Data.DataSet ds = new System.Data.DataSet();
                int count = adapter.Fill(ds, currentIndex, PageSize, "Logs");


                //Iterate through the table and in the List 
                foreach (System.Data.DataRow myDataRow in ds.Tables["Logs"].Rows)
                {
                    if (result == null)
                    {
                        result = new List<TableDat>();
                    }
                    result.Add(
                              new TableDat(
                                  (int)myDataRow[Resources.ID],
                                  (DateTime)myDataRow[Resources.TimeStamp],
                                  (int)myDataRow[Resources.EVENTLOG_SID],
                                  (int)myDataRow[Resources.EVENTLOG_EID])
                              );

                }
                // Set the dataSet object to NULL : No longer needed as the list 
                // has  been populated
                ds = null;
            }

我看到的最大问题是这会阻止SQL CE数据库工作。 Soz,我无法弄清楚我应该在异常处理中做什么,因为我的列表中没有任何内容,这意味着调用者没有列表的详细信息?

这只是表现出来的。我正在寻找一个可以处理异常的解决方案,也知道为什么我的数据库表现如此: - (

Stack Trace看起来像:

A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.IO.IOException' occurred in System.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.IO.IOException' occurred in System.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.IO.IOException' occurred in System.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.IO.IOException' occurred in System.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.IO.IOException' occurred in System.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.IO.IOException' occurred in System.dll
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll
A first chance exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.Collections.Generic.KeyNotFoundException' occurred in mscorlib.dll
KeyNotFoundException
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll

1 个答案:

答案 0 :(得分:2)

通常你不需要担心第一次机会异常。它们通常由dll中的低级代码预期和处理。

对第一次机会异常here进行了大量的报道。

您也可以在Visual Studio中disable these messages。 (对于VS 2005 ......在2008年不确定)。