1. Saul Erhmy
  2. .NET DataStore
  3. Monday, 17 October 2022 21:01 PM UTC

Hi, 

I am doing a retrieve on a datastore and then exporting the datastore into a string and writing to text file. When I open the text file I get these weird Red Nul Characters. 

When I print to console, it prints as " ".

When I check string.Contains(" "); it doesn't contain it.

When I check string.Contains("); it does contain it.

So its weird it prints to console as " " and not as "" and whats even weirder in the txt the same string prints as a red Nul

I know I can loop through each row ( i have 200,000 rows) and remove the "" string by doing dataStore[i].ColumnName1, datstore[i].columName2 ... datastore[i].columnName75. My goal is to avoid writing down all 75 datastore properties and checking if any of them contain that character and keep the same formatting in my text file. In other words instead of the red Nul just print as "" in my .txt file and keep everything else as is. 

If anyone could please help me with this I would really appreciate it. 

Thanks, 

Saul 

edit: When I do this same retrieve in PB 2022 my file isn't filled with Red Nuls. 

John Fauss Accepted Answer Pending Moderation
  1. Monday, 17 October 2022 21:40 PM UTC
  2. .NET DataStore
  3. # 1

This might be an encoding issue. PB uses Unicode-16LE encoding internally (I don't know what the .NET DataStore uses). What encoding are you using when writing the data to a text file? UTF-8?

Comment
  1. Saul Erhmy
  2. Monday, 17 October 2022 22:43 PM UTC
That I am honestly not sure. It should be the default one because I am not setting any encoding when writing data to a text file, not sure which one that is. I'll try to go through other encodings but I dont see Unicode-16LE. The ones I have available are ASCII, BigEndianUnicode, Default, Latin1, Unicode, UTF32, UTF7, UTF8. I've already tried Unicode and BigEndianUnicode but still the same results. I'm going to go through all of them, maybe one works. If none of them work what should i try to do?

  1. Helpful
  1. John Fauss
  2. Tuesday, 18 October 2022 01:49 AM UTC
Unicode-16LE is two bytes/character using Little Endian byte ordering - One byte to identify the code page and the other byte to identify the character within the code page. For "normal" text, the code page ID is zero, which is why I suspect you are seeing a NUL byte interspersed between the data bytes.

Although I know PB reasonably well, I'm unable to advise you, since I can barely spell dot-net. Please realize that since this is a PowerBuilder forum and since many of us here do not have extensive experience with C# coding, there's likely going to be some difficulty understanding each other since our respective frames of reference are so different from each other.

Roland's question is important, as that will help others (not me, unfortunately) figure out the format (and encoding) of the data you are wanting to write to a file. It will probably also be helpful to know more details about how you are writing the data to a file.
  1. Helpful 2
  1. Saul Erhmy
  2. Tuesday, 18 October 2022 16:03 PM UTC
Ok thank you I appreciate your input! I'll respond to Roland to see what he says.
  1. Helpful
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Tuesday, 18 October 2022 00:39 AM UTC
  2. .NET DataStore
  3. # 2

How are you exporting the data out of the datastore?

Comment
  1. Saul Erhmy
  2. Tuesday, 18 October 2022 16:06 PM UTC
Im exporting the datastore as a string, like so.

string dataString = datastore.ExportString(false);



and then writing to file like so

File.AppendAllText(path, dataString.Replace("\"", "")); //The replace just gets rid of quotes
  1. Helpful
There are no comments made yet.
Logan Liu @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 18 October 2022 07:44 AM UTC
  2. .NET DataStore
  3. # 3

Hi Saul,

Did you call the ExportString method to export the DataStore's data as a string?

Is this string correct if you debug and watch the string in an IDE (such as SnapDevelop)?

After calling "System.IO.File.WriteAllText("OUTPUT_FILENAME.txt", YOUR_STRING);" to save the string to a text file. you can know whether the issue occurs when writing the string to the file. 

If still not solved, could you post the sample code here?

Regards, Logan

 

     

 

Comment
  1. Saul Erhmy
  2. Tuesday, 18 October 2022 16:15 PM UTC
1. yes I am using the export string method "string dataString = datastore.ExportString(false);"

2. In an IDE the string prints as " "

3. Instead of WriteAllText I was using AppendAllText, I tried changing it to WriteAllText but no luck.

4. My code



datastore.Retrieve();

string dataString = datastore.ExportString(false);

File.AppendAllText(path, dataString.Replace("\"", "")); //The replace just gets rid of quotes



I'm doing a retrieve on 20 other dataStores too and they aren't having this issue.



  1. Helpful
  1. Logan Liu @Appeon
  2. Wednesday, 19 October 2022 09:08 AM UTC
Hi Saul,

If the other 20 DataStores don't have the same issue, could you submit a simple C# project here that can reproduce it?

If possible, you don't need to use DataContext to connect the database, please comment "retrieve" code line and Add a row by code before exporting data: https://docs.appeon.com/net_datastore/4.x/api_reference/DWNet.Data/DataStore/IDataStore_Generic/Method/Add.html

Then you can know whether this issue is related to the data stored in the database.

Regards, Logan

  1. Helpful 1
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Tuesday, 18 October 2022 10:29 AM UTC
  2. .NET DataStore
  3. # 4

Which text editor are you using?

Maybe it has an option to show null values as a 'red null'?

 

Comment
  1. Saul Erhmy
  2. Tuesday, 18 October 2022 16:21 PM UTC
I am using VSCode, I'll see if it has that option. But its weird how the .txt file I retrieve using PowerBuilder doesn't have the red nulls but a .Net Datastore retrieve has those. And I'm opening both in VSCode. Should have the same output right?
  1. Helpful
  1. Armeen Mazda @Appeon
  2. Tuesday, 18 October 2022 16:25 PM UTC
Maybe problem is the encoding option of the file? Have you tried different encodings, such as UTF16 LE BOM?
  1. Helpful
  1. Saul Erhmy
  2. Tuesday, 18 October 2022 16:39 PM UTC
I tried different Encodings, like this File.WriteAllText(path, dataString, System.Text.Encoding.GetEncoding("UTF-16LE")); I also tried Unicode and BigEndianUnicode.
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Tuesday, 18 October 2022 16:35 PM UTC
  2. .NET DataStore
  3. # 5

Is it just me or is saying that the image shows "Red Nul" incorrect?

I've put on my glasses and what I read in red is "HUL" 

I would suggest to use a hexadecimal editor to see what's in that position.

regards

Comment
  1. Saul Erhmy
  2. Tuesday, 18 October 2022 16:55 PM UTC
I used https://hexed.it to find what the value between "4" and "D" is 00 09 00 00 00 09 00. When I hover over 09 it shows that its Bit 3(8) and Bit 0(1)
  1. Helpful
  1. Miguel Leeuwe
  2. Tuesday, 18 October 2022 17:05 PM UTC
Can you attach some output as a file?
  1. Helpful
  1. Roland Smith
  2. Tuesday, 18 October 2022 18:32 PM UTC
HEX 09 is a TAB character.

Tab Null Tab

09 00 00 00 09 00

Is it possible that the .Net Datastore is exporting null values as null (00 00) while the desktop DataStore is exporting as nothing (two adjacent tabs).
  1. Helpful 3
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.