Re: BinaryStream.Write ByteArray erroring with Code 800A0BB9, Source ADODB.Stream
- From: thefabulouslb@xxxxxxxxx
- Date: Thu, 9 Apr 2009 11:04:09 -0700 (PDT)
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
.
- Follow-Ups:
- Re: BinaryStream.Write ByteArray erroring with Code 800A0BB9, Source ADODB.Stream
- From: Richard Mueller [MVP]
- Re: BinaryStream.Write ByteArray erroring with Code 800A0BB9, Source ADODB.Stream
- References:
- BinaryStream.Write ByteArray erroring with Code 800A0BB9, Source ADODB.Stream
- From: thefabulouslb
- Re: BinaryStream.Write ByteArray erroring with Code 800A0BB9, Source ADODB.Stream
- From: Richard Mueller [MVP]
- Re: BinaryStream.Write ByteArray erroring with Code 800A0BB9, Source ADODB.Stream
- From: thefabulouslb
- Re: BinaryStream.Write ByteArray erroring with Code 800A0BB9, Source ADODB.Stream
- From: Richard Mueller [MVP]
- BinaryStream.Write ByteArray erroring with Code 800A0BB9, Source ADODB.Stream
- Prev by Date: Re: WScript.dll not working
- Next by Date: Re: BinaryStream.Write ByteArray erroring with Code 800A0BB9, Source ADODB.Stream
- Previous by thread: Re: BinaryStream.Write ByteArray erroring with Code 800A0BB9, Source ADODB.Stream
- Next by thread: Re: BinaryStream.Write ByteArray erroring with Code 800A0BB9, Source ADODB.Stream
- Index(es):
Relevant Pages
|