المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : CommandBehavior.SequentialAccess (SqlDataReader)



C# Programming
03-30-2009, 05:00 AM
Can you use CommandBehavior.SequentialAccess with data in a VARBINARY column?

I have a downloads pulling from that column but not doing it that way.... here is my code:


int bytesSize = 0;
byte[] downBuffer = new byte[1024];

byte[] buffer = (byte[])cmd.ExecuteScalar();
conn.Close();

MemoryStream ms = new MemoryStream(buffer);
FileStream fs = new FileStream(Path, FileMode.Create, FileAccess.ReadWrite);

while ((bytesSize = ms.Read(downBuffer, 0, downBuffer.Length)) > 0)
{
fs.Write(downBuffer, 0, bytesSize);
WriteTextBox((fs.Length / 1024) + "KB of " + (ms.Length / 1024) + "KB.");
bw.ReportProgress(Convert.ToInt32((fs.Length * 100) / ms.Length));
}

fs.Close();
ms.Close();


The problem is it gets all the data here:

byte[] buffer = (byte[])cmd.ExecuteScalar();


So if I'm correct it is getting ALL of the data there. Which if it is a large file.. not even that large, it pauses there until it gets it.. Now on remote connections it times out because it doesn't have that long. But also the way I have it reports progress when writing to the file, but I want to report progress on downloading the file.

I have seen code used with this for BLOB data, but the column is not the type TEXT.