c# - Obtaining Sample Queries Efficiently from SQL using Entity Framework in Visual Studio -
i'm working massive database, 50gb in size. want iteratively process rows of database using entity framework provided in visual studio. current attempt follows (and fails miserably):
using (var db = new context()) { var test = (from b in db.x orderby b.id select b.y); (int = 0; < 100; i++) { var sample = test.skip(200*i).take(200); operateon(sample); } }
when code ran, past forming test, cannot form sample variable. sql times out, , visual studio gives following complaint:
unhandled exception: system.data.entity.core.entitycommandexecutionexception: error occurred while executing command definition. see inner exception details. ---> system.data.sqlclient.sqlexception: timeout expired. time out period elapsed prior completion of operation or server not res ponding. ---> system.componentmodel.win32exception: wait operation timed out
is there better way take rows using entity framework, , if so, how do it?
edit: tried implement sqlreader implementation of algorithm, same timeout error occurring:
using (sqlconnection db = new sqlconnection("connection string")) { db.open(); using (var command = db.createcommand()) { command.commandtext = "select x y order z"; using (var reader = command.executereader()) { while (reader.read()) { string response = reader.getstring(0); operateon(response); } } }
in situation, best use reader. example:
using (var db = new context()) { using (var command = db.connection.createcommand()) { command.commandtext = "select y x order id"; using (var reader = command.executereader()) { if (reader.hasrows) { while (reader.read()) { operateon(reader.getstring(0)); } } } } }
the datareader provides read only, forward only, high performance mechanism retrieve data database.
using datareader increases performance , reduces overhead because 1 row @ time ever in memory.
Comments
Post a Comment