• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 499
  • Last Modified:

Failing to get and decode Binary value from Sybase [C#]

Hi Experts

I would really appreciate your help on this one. I need to get this done asap and it doesnt seem to work.
I have a Sybase DB field "Long Binary" type that I'm pulling values from and trying to "decode" them and turn into regular strings.

To do this I create a byte[] array, read values from that Sybase field with DataReader.GetBytes into that array and then simply loop through the array to build my final string.
Simple but for some reason 30% of the time or so GetBytes returns nothing. It doesn't turn pulled in database values into the Bytes[] array and it's driving me nuts.
Can't figure out what's going on. Please help.

Here is my code
byte[] bytes = new byte[size];

reader.GetBytes(fldID, 0, bytes, 0, bytes.Length); //This for some reason doesnt populate my bytes[] array sometimes
foreach (byte b in bytes)
result = !b.Equals(DBNull.Value) ? result + Convert.ToChar(b) : result + "\0";

Open in new window

1 Solution
techsuppoprtAuthor Commented:
So is there another way to pull the bytes[] array from my DataReader because GetBytes() doesn't seem to work properly for me this way.
Anyone ?
Meir RivkinFull stack Software EngineerCommented:
try converting to string this way:

System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
string str = enc.GetString(bytes);
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now