c# - Solved:DataAdapater : StackOverFlow Exception with empty row -
i trying fill dataset
using sqldataadapter
. wrote simple function below
public static datatable getdata(string query, sqlparameter[] parameters=null) { using (reliablesqlconnection con = new reliablesqlconnection(dbutility.connectionstring)) { try { var cmd = con.createcommand(); cmd.commandtext = query; if (parameters != null) { foreach (sqlparameter p in parameters) { cmd.parameters.add(p); } } sqldataadapter da = new sqldataadapter(); da.selectcommand = cmd; dataset ds = new dataset(); //da.fillschema(ds, schematype.source); da.fill(ds); return ds.tables[0]; } catch (stackoverflowexception ex) { return null; }catch { return null; } } }
this latest modified version, when call function,
exception of type 'system.stackoverflowexception' thrown.
exception, , iis crash , close application pool on live server. (in visual studio, stop debugger ). oh, happen when query returns empty recordset, i.e. query valid return 0 rows. if data present works fine.
i search , question (how fill dataset metadata if select query return no rows) suggest use fillschema, try no change found. had "table" name define fill, remove , still no change. though piece of code in try catch
, still crashing server (i not see typical asp.net error page, 503 service not found
kind of error when happens.
edit: using .net framework 4.5.1/4.6.1 (yup try run on 2 version).
edit2 : an unhandled exception of type 'system.stackoverflowexception' occurred in system.data.dll
edit3: realise doesn't fail other query empty record, realise query fails has column "varchar(max)" datatype, testing if true, think cause of error.
failing query : select titlename, [message] tblverbiage saleid=@saleid
edit 4: try cast varchar(200), , still gives error. so, thought maybe table corrupted? did dbcc checktable
return success. notice error coming of table only.
edit 5 : turns out there logical issue in code iterate query, , hence memory leak might occur cause error.
Comments
Post a Comment