Problem saving database BLOB to file

L

Lauchlan M

I am trying to do something like in the article
http://support.microsoft.com/default.aspx?scid=kb;en-us;309158

I am however using a datareaders instead of a dataset (it's the only real
difference I can see!):

nxConnection.Open();
dtrData = (NexusDB.ADOProvider.NxDataReader)nxCommand.ExecuteReader(); //
open the data reader

if (dtrData.Read())
{
// do some other stuff that works with the row in the data reader //

...

// now try and open the BLOB, like in the example:

int ArraySize =
ArraySize = MyData.GetUpperBound(0);

byte[] ECGBLOB = new byte[0];

ECGBLOB = (byte[])dtrData["ECG_Image"];
int ArraySize = new int();
ArraySize = ECGBLOB.GetUpperBound(0); //ECGBLOB.Length;

It creashes at this last line (regardless of whether I use GetUpperBound or
Length) with

<<

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:


Line 187:
Line 188: ECGBLOB = (byte[])dtrData["ECG_Image"];
Line 189: int ArraySize = ECGBLOB.Length; //GetUpperBound(0); //new
int();
Line 190: //ArraySize = ECGBLOB.GetUpperBound(0);
Line 191:


Source File:
e:\inetpub\wwwroot\mywebinterface_nexusdb\sharedsecure\sessiondetail_ecg.asp
x.cs Line: 189

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
MyWebInterface_NexusDB.Admin.af.Page_Load(Object sender, EventArgs e) in
e:\inetpub\wwwroot\mywebinterface_nexusdb\sharedsecure\sessiondetail_ecg.asp
x.cs:189
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731
 
F

Fitim Skenderi

Hi,

If you are using dataReader, you need to use GetBytes method of the
DataReader. Check the code below:

BinaryWriter bw;
int bufferSize = 100;
MemoryStream contents = new MemoryStream(bufferSize);
byte[] buffer = new byte[bufferSize];
long retValue;
long startIndex = 0;

bw = new BinaryWriter(contents);
retValue = myReader.GetBytes(1, startIndex, buffer, 0, bufferSize);
while (retValue == bufferSize)
{
bw.Write(outbyte);
bw.Flush();
startIndex += bufferSize;
retValue = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize);
}

bw.Write(outbyte, 0, (int) (retval - 1));
bw.Flush();
bw.Close();

Now your image is storead in a memory stream.

Hope this helps

Fitim Skenderi
Lauchlan M said:
I am trying to do something like in the article
http://support.microsoft.com/default.aspx?scid=kb;en-us;309158

I am however using a datareaders instead of a dataset (it's the only real
difference I can see!):

nxConnection.Open();
dtrData = (NexusDB.ADOProvider.NxDataReader)nxCommand.ExecuteReader(); //
open the data reader

if (dtrData.Read())
{
// do some other stuff that works with the row in the data reader //

...

// now try and open the BLOB, like in the example:

int ArraySize =
ArraySize = MyData.GetUpperBound(0);

byte[] ECGBLOB = new byte[0];

ECGBLOB = (byte[])dtrData["ECG_Image"];
int ArraySize = new int();
ArraySize = ECGBLOB.GetUpperBound(0); //ECGBLOB.Length;

It creashes at this last line (regardless of whether I use GetUpperBound or
Length) with

<<

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.

Source Error:


Line 187:
Line 188: ECGBLOB = (byte[])dtrData["ECG_Image"];
Line 189: int ArraySize = ECGBLOB.Length; //GetUpperBound(0); //new
int();
Line 190: //ArraySize = ECGBLOB.GetUpperBound(0);
Line 191:


Source File:
e:\inetpub\wwwroot\mywebinterface_nexusdb\sharedsecure\sessiondetail_ecg.asp
x.cs Line: 189

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an
object.]
MyWebInterface_NexusDB.Admin.af.Page_Load(Object sender, EventArgs e) ine:\inetpub\wwwroot\mywebinterface_nexusdb\sharedsecure\sessiondetail_ecg.asp
x.cs:189
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731
 
L

Lauchlan M

If you are using dataReader, you need to use GetBytes method of the
DataReader. Check the code below:

Ah. I can't use GetBytes, it's not implemented for the dotnetprovider for
the database (NexusDB) I'm using.

I'll try switching to using a dataset or try another approach then.

Thanks for the pointers!

Lauchlan M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top