C# KeyNotFoundException:SQLCE数据库异常
我正在使用C#中的数据集。我已经做了一个项目数量的直接计数 SQL CE数据库,因此我知道数据库中有多少项。数据库中没有删除项 我收到以下无法解释的异常:C# KeyNotFoundException:SQLCE数据库异常,c#,compact-framework,sql-server-ce,C#,Compact Framework,Sql Server Ce,我正在使用C#中的数据集。我已经做了一个项目数量的直接计数 SQL CE数据库,因此我知道数据库中有多少项。数据库中没有删除项 我收到以下无法解释的异常: System.Data.SqlServerCe.dll中出现“System.Data.SqlServerCe.SqlCeException”类型的第一次意外异常 在mscorlib.dll KeyNotFoundException中发生“System.Collections.Generic.KeyNotFoundException”类型的第一
System.Data.SqlServerCe.dll中出现“System.Data.SqlServerCe.SqlCeException”类型的第一次意外异常
在mscorlib.dll KeyNotFoundException中发生“System.Collections.Generic.KeyNotFoundException”类型的第一次意外异常 这显示了与SQL CE数据库的通信锁定的位置 有人知道这是什么原因吗?如何解决 我在网上搜索过,但没有找到任何解决方案:-(
通常情况下,您不必担心第一次出现异常。它们通常是由dll中的较低级别代码预期和处理的 关于第一次机会的例外情况有一篇不错的评论
您也可以在Visual Studio中使用(对于VS 2005…2008年不确定)。我还将包括这两个例外的完整堆栈跟踪—不需要将ds分配给null(实际上可能会导致性能降低)DataSet还实现了IDisposable,因此您应该将其放入一个块中。在不属于您控件的对象上使用块锁定也是一种不好的做法。您不知道其他人是否正在使用同一对象进行锁定(尽管这也是一种不好的做法)并可能导致死锁System.Data.SqlServerCe.SqlCeException类型的第一次机会异常发生在System.Data.SqlServerCe.dll中System.Data.SqlServerCe.SqlCeException类型的第一次机会异常发生在System.Data.SqlServerCe.dll中mscorlib.dll中System.FormatException类型的第一次机会异常第一次机会mscorlib.dll中出现“System.FormatException”类型的异常mscorlib.dll中出现“System.Collections.Generic.KeyNotFoundException”类型的第一次意外异常KeyNotFoundException没有更改,因为我已经取消将所有输出窗口文本重定向到即时窗口的设置。一旦收到异常,它将停止数据库访问。Pl你能进一步解释一下吗?是什么导致这些?我怎样才能摆脱它们??
// 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;
}
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