2009-09-07 6 views
0

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 
+1

Je comprendrait également la trace complète de la pile des deux exceptions – ShuggyCoUk

+0

une part - la cession de DS à nul n'est pas nécessaire (et peut effectivement causer une dégradation des performances) DataSet – ShuggyCoUk

+0

met également en œuvre IDisposable vous devriez le mettre dans un bloc à l'aide – ShuggyCoUk

Répondre

2

En général, vous ne avez pas vraiment besoin de vous inquiéter exceptions de première chance. Ils sont généralement anticipés et gérés par le code de niveau inférieur à l'intérieur de la DLL.

Il existe une description correcte des exceptions de première chance here. Vous pouvez également disable these messages dans Visual Studio. (Pour VS 2005 ... pas sûr sur 2008).

+0

Pas de changements car j'ai déjà désactivé le texte Rediriger tous les fenêtres de sortie dans la fenêtre Exécution.Une fois que j'obtiens l'exception, il arrête l'accès à la base de données –

+0

exceptions dans le code non-utilisateur, mais généralement assez sérieux –

+0

S'il vous plaît pouvez-vous expliquer cela plus loin? Qu'est-ce qui peut causer ces ?? Comment puis-je me débarrasser d'eux ?? –

Questions connexes