c# - Call to sybase stored procedure doesn't always return correct number of rows when using the data -
i'm having simple application calling stored procedure in sybase using odbcconnection. think working inconsistent , can't tell why.
after calling stored procedure put in list> , make result xml , save on disc.
when running application , calling same stored procedure different results every once , while. stored procedure simple , should return 1800 rows.
sp:
select column1 ,column2 database..table
call database:
public list<dictionary<string, object>> getdatafromdb(string dbconnection, string sp) { var result = new list<dictionary<string, object>>(); using (var con = new odbcconnection(dbconnection)) { con.open(); using (var cmd = con.createcommand()) { cmd.commandtype = commandtype.storedprocedure; cmd.commandtext = sp; cmd.commandtimeout = 15; var reader = cmd.executereader(); result = getdatafromquery(reader); } } return result; } private list<dictionary<string, object>> getdatafromquery(idatareader reader) { var cols = new string[reader.fieldcount]; (var ordinal = 0; ordinal < reader.fieldcount; ordinal++) cols[ordinal] = reader.getname(ordinal); var retlist = new list<dictionary<string, object>>(); while (reader.read()) retlist.add(cols.todictionary(t => t, t => reader[t])); return retlist; }
and xml method:
public xdocument toxml(string collectionname, ienumerable<dictionary<string, object>> data) { xml = new xdocument( new xelement("table", new xattribute("name", collectionname), x in data select new xelement("row", x.select(y => new xattribute(y.key, y.value))))); }
to save xml use .save(path).
so, getdatafromdb not return rows should, time. it's working mostly, maybe 1 out of 5 wrong. i've tried put reader datatable , count rows, , it's 1800. somewhere rows getting lost, guess getdatafromquery... xml contains 300 rows, , 1800.
can me see problem is?
Comments
Post a Comment