Author Topic: Problems using ADODB.Stream in JavaScript  (Read 4685 times)

nilspc

  • EA User
  • **
  • Posts: 28
  • Karma: +1/-0
    • View Profile
Problems using ADODB.Stream in JavaScript
« on: January 02, 2023, 09:08:53 pm »
Hi,
I'm importing files in UTF-8 format and Scripting.FileSystemObject apparently does not support UTF-8. When importing nordic characters are randomly corrupted so I'm testing using ADODB.Stream instead.
The code work in JScript but NOT in JavaScript. The JavaScript code runs with no errors but the file appears to be empty.
Can anyone explain why it works in JScript but not in JavaScript?  se the code below
Or rather, how I can get it to work in JavaScript (prefer JavaScript because of the built-in debugger)

Running 16.1

Regards
Nils

JavaScript
Code: [Select]
var fileName;
var file;
fileName = "c:/temp/storutftestfil.csv";
var stream = new COMObject("ADODB.Stream");
stream.Type = 2 // text data (as apposed to binary data)
stream.Charset = "utf-8";
stream.LineSeparator = -1; // carriage return line feed
stream.Open();
stream.LoadFromFile = fileName;
file = stream.ReadText();
Session.Output("Stream : " + stream.Size);
Session.Output("Line : " + file);
stream.Close();

JScript
Code: [Select]
var fileName;
var file;
fileName = "c:/temp/storutftestfil.csv";
var stream = new ActiveXObject("ADODB.Stream");
stream.Type = 2 // text data (as apposed to binary data)
stream.Charset = "utf-8";
stream.LineSeparator = -1; // carriage return line feed
stream.Open();
stream.LoadFromFile = fileName;
file = stream.ReadText();
Session.Output("Stream : " + stream.Size);
Session.Output("Line : " + file);
stream.Close();

« Last Edit: January 03, 2023, 12:18:06 am by nilspc »

dge98753

  • EA Novice
  • *
  • Posts: 9
  • Karma: +0/-0
    • View Profile
Re: Problems using ADODB.Stream in JavaScript
« Reply #1 on: January 04, 2024, 02:55:31 am »
The post is old so I think the answer is no longer expected but if anyone goes through it there will be the answer.
I came across the same thing.
The issue is that the LoadFromFile is not an attribut but a function.

Here is the correction:
Code: [Select]
var fileName;
var file;
fileName = "c:/temp/storutftestfil.csv";
var stream = new COMObject("ADODB.Stream");
stream.Type = 2 // text data (as apposed to binary data)
stream.Charset = "utf-8";
stream.LineSeparator = -1; // carriage return line feed
stream.Open();
stream.LoadFromFile(fileName);
file = stream.ReadText();
Session.Output("Stream : " + stream.Size);
Session.Output("Line : " + file);
stream.Close();

nilspc

  • EA User
  • **
  • Posts: 28
  • Karma: +1/-0
    • View Profile
Re: Problems using ADODB.Stream in JavaScript
« Reply #2 on: January 16, 2024, 07:58:26 pm »
Hi,

Thank you ;D
Seems to work

Regards
Nils