questioni about SqlBytes class

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following code

System.Data.SqlTypes.SqlBytes bytes = reader.GetSqlBytes(columnIndex);
MemoryStream ms = new MemoryStream(bytes.Buffer);

My question is will the Buffer property of SqlBytes reliable get all the
data from the bytes retreived from the GetSqlBytes function. It seems to do
so in my testing but will this always be the case. The documentation is a bit
sparse on this. It was the only way I could find to populate a memory stream
from the SqlBytes.
 
What bother you really?? If it is working alright
Because it might be working just in the cases he has tested and could maybe
still fail in a "real life" situation.
So he (rightfully) wants documentation that states that it will always behave
this way.

Hans Kesting
 
Your test cases indeed should cover the real life situation, else what is
the point of that test??

Nirosh.
 
Scott,

Unless you have to manupulate the values of the bytes, you should just
call the Stream property on the SqlBytes instance. This will return a
stream of bytes that taps into the TDS stream that SQL Server returns. If
you call the Buffer property, it will read the entire contents of the stream
into memory. It's not the MemoryStream that is helping you, it is the call
to Buffer.

As for will it always be reliable? Well, no, but that's the nature of
things. Any number of things could go wrong. What if someone pulls the
network cord while reading the contents from the stream?

Hope this helps.
 
Your test cases indeed should cover the real life situation, else what
is the point of that test??

Nirosh.

Maybe I should have said "*unforseen* real life situation". You can only test
against situations that you expect.

And if the docs state "it will always behave like this", you don't have to
test
that against every imaginable situation.

Hans Kesting
 

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

Back
Top