'System.StackOverflowException' occurred in System.Data.SqlServerCe.dll
<p>I'm using <strong>SQL CE 4.0</strong> and am running into a <strong>StackOverflowException</strong> when the <strong>SqlCeDataAdapter</strong> attempts to <strong>Fill</strong> the <strong>DataTable</strong>. </p>

<p>The code is pretty standard :</p>

<pre class="lang-cs prettyprint-override"><code>using (var cmd = new SqlCeCommand(sql, conn, tran))
using (var dt = new DataTable())
{
    using (var da = new SqlCeDataAdapter(cmd))
        da.Fill(dt);

    IList&lt;DataRow&gt; rows = dt.Rows.OfType&lt;DataRow&gt;().ToList();
    foreach (DataRow row in rows)
    {
        // Processing ...
    }
}
</code></pre>

<p>The <code>sql</code> string is in the form of :</p>

<pre class="lang-sql prettyprint-override"><code>SELECT * FROM [Table] WHERE Id IN ( ... )
</code></pre>

<p>The total character count is <code>1,068,369</code> due to the column value list being filled with <code>27,393</code> values of type <code>uniqueidentifier</code>. </p>

<p>Executing that query should return results with 1-for-1 rows from the database. Instead, the <strong>StackOverflowException</strong> occurs. I feel as though I am running up against some sort of <strong>SQL CE 4.0</strong> limitation. </p>

<hr>

<p>I've read <a href="https://msdn.microsoft.com/en-us/library/ms172451.aspx" rel="nofollow">Understanding Databases (SQL Server Compact) > Database Objects</a> and under the <strong>Queries</strong> section it reads :</p>

<blockquote>
  <p>Characters in an SQL statement &nbsp;&nbsp; | &nbsp;&nbsp; Unlimited</p>
</blockquote>

<p><code>1,068,369</code> characters is less than <code>unlimited</code>; <strong>PASS</strong>.</p>

<hr>

<p>I've read <a href="https://msdn.microsoft.com/en-us/library/system.data.datatable(v=vs.110).aspx" rel="nofollow">DataTable Class</a> and under the <strong>Remarks</strong> section it reads :</p>

<blockquote>
  <p>The maximum number of rows that a DataTable can store is <strong>16,777,216</strong></p>
</blockquote>

<p><code>27,393</code> rows is less than <code>16,777,216</code>; <strong>PASS</strong>.</p>

<hr>

<p>Is there something else that I'm missing?</p>