简体   繁体   中英

'System.StackOverflowException' occurred in System.Data.SqlServerCe.dll

I'm using SQL CE 4.0 and am running into a StackOverflowException when the SqlCeDataAdapter attempts to Fill the DataTable .

The code is pretty standard :

using (var cmd = new SqlCeCommand(sql, conn, tran))
using (var dt = new DataTable())
{
    using (var da = new SqlCeDataAdapter(cmd))
        da.Fill(dt);

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

The sql string is in the form of :

SELECT * FROM [Table] WHERE Id IN ( ... )

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

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


I've read Understanding Databases (SQL Server Compact) > Database Objects and under the Queries section it reads :

Characters in an SQL statement | Unlimited

1,068,369 characters is less than unlimited ; PASS .


I've read DataTable Class and under the Remarks section it reads :

The maximum number of rows that a DataTable can store is 16,777,216

27,393 rows is less than 16,777,216 ; PASS .


Is there something else that I'm missing?

"The code is pretty standard" (!) - but the SQL statement is not! It is obviously an engine bug/doc error, but do not expect a fix from Microsoft. You will have to change the code to work with smaller batches of ids, resulting in a statement that is not 1 MB in size with 27.000 values.

This sounds like your sql server runs out of temp space when running this query. You can test this by changing the query to return only one row and not using the IN statement. if this works then as mentioned before check or ask your DBA to check that the system has been allocated the resources to run the query and build the result set before returning it to your application. PS. IF multiple persons use this application at the same time then this problem will scale horribly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM