Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2454
  • Last Modified:

how to store a BLOB data on a windows file using vbscript?

i have a vbscript that retrieves image data (blob) from an oracle database. i need a vbscript code that will take this image data (blob) and write it to a windows file that can be viewed as a .jpg file.
thanks.
0
alidabiri
Asked:
alidabiri
  • 4
  • 4
1 Solution
 
alidabiriAuthor Commented:
WHEN I first joined expert exchange, it was because there was a solution listed for this question which said "it has been tested and verified - join to vew to solution."
however, after joining it was found out that the solution IS NOT FOR VB SCRIPT and the poster wanted the code to be "modified" to fit VB SCRIPT. this is not a very professional way of attracting members to join. i'm really disappointed.
0
 
Robert SchuttSoftware EngineerCommented:
I can imagine you are disappointed but let's hope that's a one in a million.

I have a solution for you, for speed when saving to disk I use a function found elsewhere on the net (see ref in code).

Fill in the const fields, make a subdir "files" (or adjust the code) and you should be golden.
Option Explicit

Const C_ORA_SID = "XE"
Const C_ORA_USR = "USER"
Const C_ORA_PWD = "PASSWORD"

Const C_TBL = "TABLE"
Const C_FLD_LOB = "LOB_FIELD"
Const C_FLD_ID = "ID_FIELD"

Dim oConn, sSQL, oRst, oLOB, f
Set oConn = CreateObject("ADODB.Connection")
oConn.ConnectionString = "Provider=ORAOLEDB.ORACLE;Data Source=" & C_ORA_SID & ";User ID=" & C_ORA_USR & ";Password=" & C_ORA_PWD & ";"
oConn.Open
sSQL = "SELECT " & C_FLD_ID & ", " & C_FLD_LOB & " FROM " & C_TBL
Set oRst = oConn.Execute(sSQL)
While Not oRst.EOF
	oLOB = oRst.Fields(1).Value
	If Not IsNull(oLOB) Then
		SaveBinaryData "files\file_" & oRst.Fields(0) & ".jpg", oLOB
	End If
	oRst.MoveNext
Wend
oRst.Close
Set oRst = Nothing
oConn.close
Set oConn = Nothing

' from http://www.motobit.com/tips/detpg_read-write-binary-files/
Function SaveBinaryData(FileName, ByteArray)
	Const adTypeBinary = 1
	Const adSaveCreateOverWrite = 2

	'Create Stream object
	Dim BinaryStream
	Set BinaryStream = CreateObject("ADODB.Stream")

	'Specify stream type - we want To save binary data.
	BinaryStream.Type = adTypeBinary

	'Open the stream And write binary data To the object
	BinaryStream.Open
	BinaryStream.Write ByteArray

	'Save binary data To disk
	BinaryStream.SaveToFile FileName, adSaveCreateOverWrite

	BinaryStream.Close
	Set BinaryStream = Nothing
End Function

Open in new window

0
 
alidabiriAuthor Commented:
unfortunately i'm getting an error message:
error: write to file failed
code: 800A0BBC
any suggestions?
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
alidabiriAuthor Commented:
it worked. i had to specify the server directory .
thanks.
0
 
Robert SchuttSoftware EngineerCommented:
Ok, I hope that went some way towards restoring your trust in this community.

Is there anything else I can do?
0
 
alidabiriAuthor Commented:
that was great. all working ok.
thanks you so much.
0
 
Robert SchuttSoftware EngineerCommented:
Ok then, only one thing left for you to do and that is close off the question. After the criticism you had on this forum it would be very nice if you would feel inclined to help make it better.
0
 
Robert SchuttSoftware EngineerCommented:
Thanks!
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

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