- Stack Overflow can be caused by having combination of:
1) too many Rows in the DataTable
2) too many OR/AND expressions in the filter string (also see
http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3033750&SiteID=1 )
3) too long colomn names.
- I tried catching the exception and for some reason it could not be caught. Proabbly because this is an infinite loop/recurssion type of exception and process is not around to even throw the exception.
- The definition of "too long" and "too many" is not clear.
- Following program can be used to cause stack overflow exception. Set different values for the factors in the program and test to see results:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
namespace Datatable Tester
{
class Program
{
static void Main(string[] args)
{
DataTable dt = newDataTable("test");
string filter = "";
/* following factors could cause the overflow */
string cname = "col";
int colmax = 50;
int rowsmax = 50;
int linesmax = 40;
int factor = 20;
for (int col = 1 ;col <= colmax ;col ++)
dt.Columns.Add(cname + col.ToString());
for ( int rows = 0 ;rows< rowsmax; rows++)
dt.Rows.Add(123411, 234122, 123423, 12341244, 1234, 13412346, 123417, 12341, 123419);
for(int num = 0; num < linesmax; num++)
for (int i =1 ; i <= colmax; i++)
{
filter = filter +
" " + cname + i.ToString() + " = " + (i * factor).ToString() + " OR ";
}
filter = filter +
" " + cname + "1 = null";
/* Even though the exception is handled, its not getting caught */
try {
DataRow[] dr = dt.Select(filter);
}
catch (Exception se) {
Console.WriteLine(se.Message);
}
}
}
}