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

Posted on 2012-08-16
Last Modified: 2012-08-30
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.
Question by:alidabiri

    Author Comment

    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.
    LVL 35

    Accepted Solution

    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 & ";"
    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
    Set oRst = Nothing
    Set oConn = Nothing
    ' from
    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.Write ByteArray
    	'Save binary data To disk
    	BinaryStream.SaveToFile FileName, adSaveCreateOverWrite
    	Set BinaryStream = Nothing
    End Function

    Open in new window


    Author Comment

    unfortunately i'm getting an error message:
    error: write to file failed
    code: 800A0BBC
    any suggestions?

    Author Comment

    it worked. i had to specify the server directory .
    LVL 35

    Expert Comment

    by:Robert Schutt
    Ok, I hope that went some way towards restoring your trust in this community.

    Is there anything else I can do?

    Author Comment

    that was great. all working ok.
    thanks you so much.
    LVL 35

    Expert Comment

    by:Robert Schutt
    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.
    LVL 35

    Expert Comment

    by:Robert Schutt

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
    I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now