Re: BinaryStream.Write ByteArray erroring with Code 800A0BB9, Source ADODB.Stream

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Apr 8, 6:12 pm, "Richard Mueller [MVP]" <rlmueller-
nos...@xxxxxxxxxxxxxxxxxxxx> wrote:
<thefabulou...@xxxxxxxxx> wrote in message

news:79971d8f-0eb5-4d1d-8cb8-b5d30c52b5eb@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Apr 8, 9:56 am, "Richard Mueller [MVP]" <rlmueller-





nos...@xxxxxxxxxxxxxxxxxxxx> wrote:
<thefabulou...@xxxxxxxxx> wrote in message

news:12a8d0e6-8559-43a1-936e-bd7faa2c1661@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Hello,

I am new to VBScript and am trying to troubleshoot a script. The
script is reaching out to a SQLServer database and grabbing some data
and trying to drop each record into a file on my local Windows Server
2003 file system. I have been Googling for the solution, but am
having no luck. Can someone point to some possible solutions,
please? This is the error I am getting:

Line: 63 (BinaryStream.Write ByteArray)
Char: 5
Error: Arguments are of the wrong type, are out of acceptable range,
or are in conflict with one another
Code: 800A0BB9
Source: ADODB.Stream

option explicit

const ADTYPETEXT = 2
const ADOPENKETSET = 1
const ADLOCKOPTIMISTIC = 3

dim oCn
dim oRS
dim o St

set oCn = Wscript.CreateObject("ADODB.Connection")
oCn.ConnectionString = "Driver=
{SQLServer};Server=<ipaddress>;Database=<dbname>;Uid=<userid>;Pwd=<password­­>;"
oCn.Open

set oRs = oCn.execute("EXEC ABC.GetDocumentsByDateRange '10/25/2008',
'1/1/2009''")
'wscript.echo(oRs(0)) 'id
'wscript.echo(oRs(1)) ' category
'wscript.echo(oRs(2)) 'type
'wscript.echo(oRs(3)) 'title
'wscript.echo(oRs(4)) 'filename
'wscript.echo(oRs(5)) 'binary
'wscript.echo(oRs(6)) 'date
'wscript.echo(oRs(7)) 'date
'wscript.echo(oRs(8)) 'date
'wscript.echo(oRs(9)) 'short classification
'wscript.echo(oRs(10)) 'long classification

while not oRs.eof
SaveBinaryData oRs(4), oRs(5), "ABC-" & oRs(1) & "-" & oRs(2)
oRs.MoveNext
wend

oRs.Close
oCn.Close
Set oRs = Nothing
Set oSt = Nothing
Set oCn = Nothing
wscript.echo("Work Complete")

Function SaveBinaryData(Filename,ByteArray,DirName)
Const adTypeBinary = 1
Const adSaveCreateOverWrite = 2

dim fso
DirName = replace(DirName,"\","")
DirName = replace(DirName,"'","")
DirName = replace(DirName,"/","")
DirName = replace(FileName, "\","")
DirName = replace(FileName, "'","")
DirName = replace(FileName, "/","")
set fso = CreateObject("Scripting.FileSystemObject")
if fso.FolderExists("e:\data\" & DirName) = False then
fso.CreateFolder("e:\data\" & DirName)
end if

dim BinaryStream
Set BinaryStream = CreateObject("ADODB.Stream")

BinaryStream.Type = adTypeBinary
BinaryStream.Open
BinaryStream.Write ByteArray <== ******this is Line 63,
where it's failing
BinaryStream.SaveToFile "e:\data\ABC\" & FileName,
adSaveCreateOverWrite
End Function

I would check to make sure that TypeName(oRs(5)) = "Byte()", and if so,
check with UBound that the array is not empty.

--
Richard Mueller
MVP Directory Services
Hilltop Lab -http://www.rlmueller.net
--- Hide quoted text -

- Show quoted text -

Hi Richard,

I have never looked at VBScript before today.  How do I check to make
sure that TypeName(oRs(5)) = "Byte()"?  Could you also explain in more
detail about UBound?  Are these things I need to look at in SQLServer?

Thank you.

-----------

Your error message indicates an argument of the wrong type. The
BinaryStream.Write method expects a byte array, since you specified
adTypeBinary. I was suggesting that you make sure that oRs(5), or ByteArray
in the function, is datatype Byte(), which is a byte array. I think it can
also be Variant(), which is a variant array, as long as each element is an
integer in the proper range (say between 0 and 255). In any case, the
VBScript function TypeName returns the datatype of any variable reference..
In addition, if the variable refers to an array, the UBound function returns
the upper bound of the array. For example:
========
set oCn = Wscript.CreateObject("ADODB.Connection")
oCn.ConnectionString =
"Driver={SQLServer};Server=<ipaddress>;Database=<dbname>;Uid=<userid>;Pwd=<­password>;"
oCn.Open

set oRs = oCn.execute("EXEC ABC.GetDocumentsByDateRange '10/25/2008',
'1/1/2009''")

while not oRs.eof
    strType = TypeName(oRs(5).Value)
    If (strType = "Byte()") Or (strType = "Variant()") Then
        Wscript.Echo "ID: " & oRs(0).Value & ";" & strType _
            & " (" & UBound(oRs(5).Value) & ")"
    Else
        Wscript.Echo "ID: " & oRs(0).Value & ";" & strType
    End If
    oRs.MoveNext
wend
=======
The above loops through the rescordset and checks the datatype of the
"binary" on every row.

--
Richard Mueller
MVP Directory Services
Hilltop Lab -http://www.rlmueller.net
--- Hide quoted text -

- Show quoted text -

Hi again Richard,

Thank you for explaining in more detail what you were asking me to
try. I made the changes to the script using your code, and the result
I am getting is a pop-up box that loops through the recordset and
displays (example): ID: 27654; Date

This leads me to believe that oRs(5) is not a "Byte()", but rather a
Date datatype. I have been executing this script weekly for five
months straight and never had any problems with it until a few weeks
ago. The first thing I did was ask the owners of the SQLServer
database if anything on their end had changed that would affect my
script, and they said NO. I am going to go check with them again now
to verify the columns and order that these columns are being returned
to me in my record set. Something must have changed on their end,
right??!!

Laura
.



Relevant Pages

  • Re: finding files
    ... I'm back and also my script as changed ever since. ... have to be an Array then.. ... For Each strComputer In arrComputers ...     Function ReadTxtToArray ...
    (microsoft.public.scripting.vbscript)
  • Re: how can a executing bash script be paused?
    ... I admit that I haven't done any interactive input since I started ...     processing ... ... this is the script that I am trying to debug. ... in the array already). ...
    (comp.unix.shell)
  • Re: how can a executing bash script be paused?
    ...     processing ... ... this is the script that I am trying to debug. ... in the array already). ...
    (comp.unix.shell)
  • Re: how can a executing bash script be paused?
    ... I admit that I haven't done any interactive input since I started ...     processing ... ... in the array already). ...  The script does not produce output as it is ...
    (comp.unix.shell)
  • Re: Logon script - function array and select case not working
    ... this all works well, except, the function i am using for the rules in the control script causes alot of querrys to AD. as there are alot of groups. ... objTSout.writeline retrv ... So if you think that this will assign an array value to the variable, how do you think the case select statement is going go compare this array value with the literal string values such as "group name here"? ... However, by not assigning ANY value to checkgrp in the function, you are guaranteeing that, should the function ever exit, it will return no information. ...
    (microsoft.public.scripting.vbscript)