title: WinCE7 0xc0000005 Native exception on Execute reader
body: <p>I am developing a simple application for Motorola MC32N0 on WinCE7.0 using VS2008 SP1 having .net Compact Framework 3.5 and SQL Server CE 3.5SP1. </p>
  
  <p>Whenever I try to read from database I get this error.</p>
  
  <blockquote>
    <p>A native exception has occurred in projectName.exe. Select Quit and then restart this program or select details for more information.</p>
  </blockquote>
  
  <p>When I go to details I get this</p>
  
  <blockquote>
    <p>ExceptionCode: 0xc0000005<br>
    ExceptionAddress: 0xc0000000<br>
    Reading: 0xc0000000<br>
    at NativeMethods.GetKeyInfo(IntPtrpTx, String pwszBase Table, IntPtr prgDbKeyInfo, Int32 cDbKeyInfo,IntPtr pError)<br>
    at SqlCeDataReader.FillMetaData(SqlCeDataReader reader, Int32 resultType) . . .</p>
  </blockquote>
  
  <p>it continues. This is the database read code</p>
  
  <pre><code>public List&lt;Users&gt; SelectByUserName(string UserName)
  {
      var list = new List&lt;Users&gt;();
      using (var command = EntityBase.CreateCommand(Transaction))
      {
          if (UserName != null)
          {
              command.CommandText = "SELECT * FROM Users WHERE UserName=@UserName";
              command.Parameters.Add("@UserName", SqlDbType.NVarChar);
              command.Parameters["@UserName"].Value = UserName;
          }
          else
              command.CommandText = "SELECT * FROM Users WHERE UserName IS NULL";
  
          using (var reader = command.ExecuteReader())
          {
              list = fetchData(reader);
          }
      }
      return list;
  }
  </code></pre>
  
  <p>When it reaches this <code>command.ExecuteReader()</code> the exception occurs.</p>
  
  <p>After a lot of searching some guys are saying that this might be a mismatch of the SQL Server CE version but how do I fix that? One file is copied to folder when application is deployed. How to check it's version or change the version of SQL Server CE being used?</p>