What do you call "very big"? And what is a string? CLOB? Blob? XML?
I suspect you should use things like ExecuteReader() , which (via IDataReader ) provides methods for reading such columns in pieces:
using (var reader = cmd.ExecuteReader( CommandBehavior.SequentialAccess)) { char[] buffer = new char[8040]; // or some multiple (sql server page size) while (reader.Read()) { long dataOffset = 0, read; while((read = reader.GetChars(colIndex, dataOffset, buffer, 0, buffer.Length)) > 0) { // process "read"-many chars from "buffer" dataOffset += read; } } }
Obviously, with xml, you might need an XmlReader through cmd.ExecuteXmlReader() .
Updated re LINQ comment (now deleted):
To use IDataReader directly from LINQ-to-SQL, I expect that closest you will get ctx.GetCommand() by passing it a query. Then you would use ExecuteReader or ExecuteXmlReader as above. I'm not very good at EF ...
If you give an example of a query type that fails, some tricks are possible - for example, if you filter or select a subset of xml, there are things you can do in SQL / XML - perhaps in UDF called through LINQ-to-SQL.
Marc gravell
source share