Streaming VARBINARY data from SQL Server in C# -


i'm trying serve image data stored in varbinary(max) field in database using asp.net. right now, code filling data table, pulling byte array out of datarow , pushing byte array response. i'm wondering if there's way more-or-less stream data sql server response without having marshal around these huge byte arrays (since images large, cause outofmemoryexceptions). there class/mechanism that?

the current code looks more or less like:

datatable table = new datatable(); sqldataadapter adapter = new sqldataadapter(commandtext, connectionstring); adapter.fill(table); datarow row = table.rows[0]; byte[] imagedata = row[0] byte[]; if(imagedata != null) {   response.clear();   response.binarywrite(imagedata);   response.end(); } 

thanks in advance - appreciated.

see download , upload images sql server article covering topic, including efficient streaming semantics. must use sqldatareader opened commandbehavior.sequentialaccess:

sequentialaccess provides way datareader handle rows contain columns large binary values. rather loading entire row, sequentialaccess enables datareader load data stream. can use getbytes or getchars method specify byte location start read operation, , limited buffer size data being returned.

the linked article provides full code creating stream backed sqldatareader, can stream.copyto(httpresponse.outputstream), or use byte[] chunked copy if don't have .net 4.0 yet.

this follow article explains how use filestream column efficient streaming of large varbinary data in , out of database.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -