SQL is designed to work with huge datasets and is extremely efficient. Using established logic, it is often not necessary to iterate over data to perform operations, and there are a number of built-in ways to do this in SQL itself.
1) a record based on a data set for updating data without cursors
2) use deterministic user functions with set-based logic (you can do this using the SqlFunction attribute in the CLR code ). The non-deterministic effect will affect the inclusion of the query inside the cursor, which means that the output of the value is not always the same, given the same input.
[SqlFunction(IsDeterministic = true, IsPrecise = true)] public static int algorithm(int value1, int value2) { int value3 = ... ; return value3; }
3) use cursors as a last resort. This is a powerful way to execute logic in a database row, but has a performance impact. It looks like this CLR article may not execute SQL cursors (thanks to Martin).
I noticed that the complexity of using set-based logic is too great. Can you give an example? There are many SQL methods for solving complex problems - CTE, Views, partitioning, etc.
Of course, you may well be right in your approach, and I donβt know what you are trying to do, but my gut says that they use SQL tools. Multiple reader malfunctioning is the wrong approach to database implementation. You may need to have multiple threads invoke the SP to start parallel processing, but do not do this inside the CLR.
To answer your question, with CLR implementations (and IDataReader ), you really don't need to output pages to pieces, because you are not loading data into memory or transferring data over the network. IDataReader gives you access to the data stream row by row. From the sounds, this is your algorithm that determines the number of records that need updating, so when this happens, just stop calling Read() and end at that point.
SqlMetaData[] columns = new SqlMetaData[3]; columns[0] = new SqlMetaData("Value1", SqlDbType.Int); columns[1] = new SqlMetaData("Value2", SqlDbType.Int); columns[2] = new SqlMetaData("Value3", SqlDbType.Int); SqlDataRecord record = new SqlDataRecord(columns); SqlContext.Pipe.SendResultsStart(record); SqlDataReader reader = comm.ExecuteReader(); bool flag = true; while (reader.Read() && flag) { int value1 = Convert.ToInt32(reader[0]); int value2 = Convert.ToInt32(reader[1]);