uploading and saving BLOB to database?

  • Thread starter Thread starter Lauchlan M
  • Start date Start date
L

Lauchlan M

Hi

I want to upload a general BLOB (jpg, doc, pdf etc) to the database.

My code for this is at the moment something like

<<

if (
(fileDischargeFile.PostedFile != null) // there is an uplaoded file
& (fileDischargeFile.PostedFile.ContentLength !=0 ) ) // of non-zero
length
{

//Get the posted file
System.IO.Stream fileDataStream =
fileDischargeFile.PostedFile.InputStream;

//Get length of file
int fileLength = fileDischargeFile.PostedFile.ContentLength;

//Create a byte array with file length
byte[] fileData = new byte[fileLength];

//Read the stream into the byte array
fileDataStream.Read(fileData,0,fileLength);

lblUploadMessage.Text = fileData.Length.ToString(); // check we got
it - testing only - (*)

// load up the data reader so we can write the file into the BLOB
field:
nxCommand_UpdateDischargeFile.Parameters["SessionID"].Value =
Request.QueryString["SessionDataID"];

nxCommand_UpdateDischargeFile.Parameters["DischargeSummaryAmendment"].Value
= fileData;
nxConnection.Open();
nxCommand_UpdateDischargeFile.ExecuteNonQuery();
nxConnection.Close();

What happens is that it all appears to work, it tells me it's uploaded file
of say 25,321 bytes (in line *, above), but when I have a look at the BLOB
in the database there appears to be nothing there.

Is the above correct, andd is it the best way to generally load a BLOB into
the database?

Thanks!

Lauchlan M
 
Hi, Lauchlan M,

What happens is that it all appears to work, it tells me it's uploaded file
of say 25,321 bytes (in line *, above), but when I have a look at the BLOB
in the database there appears to be nothing there.

How do you know there is nothing? Do you try to read from this field?

Have a look at the following article:

http://support.microsoft.com/?kbid=326502

Although VB.NET is used you might find it useful.
Is the above correct, andd is it the best way to generally load a BLOB into
the database?

Thanks!

Lauchlan M

Greetings
Martin
 
What happens is that it all appears to work, it tells me it's uploaded
file

How do you know there is nothing? Do you try to read from this field?

Because I wrote some Delphi code to unload the BLOB from the database and it
tells me the length is zero, and also when I look at it in the database
Enterprise Manager it looks empty (actually it has about 4 byte characters
in it).
Have a look at the following article:

http://support.microsoft.com/?kbid=326502

Although VB.NET is used you might find it useful.

OK, looking. The C# version is at
http://support.microsoft.com/default.aspx?scid=kb;en-us;309158

Thanks!

Lauchlan M
 
Back
Top