J'utilise un ensemble de données en C#. J'ai fait un compte direct pour le nombre d'éléments dans la base de données SQL CE, donc je sais combien d'éléments que j'ai dans la base de données. Il n'y a pas de suppressions dans la base de données.KeyNotFoundException: Exception de base de données SQLCE
je reçois l'exception inexpliquée suivant (s):
Une première chance exception du type 'System.Data.SqlServerCe.SqlCeException' est produite dans System.Data.SqlServerCe.dll
A exception de première chance de type 'System.Collections.Generic.KeyNotFoundException' s'est produite dans mscorlib.dll KeyNotFoundException
Ceci se manifeste lorsque la communication se verrouille avec la base de données SQL CE.
Est-ce que quelqu'un sait ce qui cause cela et comment cela peut-il être corrigé?
J'ai cherché en ligne et je ne pas avoir de chance à toutes les solutions pour cette :-(
// 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;
}
Le plus gros problème que je vois est que cela arrête la base de données SQL CE travail. Soz, je ne peux pas faire ce que Je devrais faire dans la gestion des exceptions ici car je n'obtiens rien dans ma liste ce qui signifie que l'appelant n'a aucun détail pour la liste?
Cela se manifeste simplement. \ R \ n \ r \ n Je cherche une solution qui peut manipuler l'exception et aussi savoir pourquoi ma base de données se comporte comme telle :-(
Stack Trace ressemble à:
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
Je comprendrait également la trace complète de la pile des deux exceptions – ShuggyCoUk
une part - la cession de DS à nul n'est pas nécessaire (et peut effectivement causer une dégradation des performances) DataSet – ShuggyCoUk
met également en œuvre IDisposable vous devriez le mettre dans un bloc à l'aide – ShuggyCoUk