Link to home
Start Free TrialLog in
Avatar of BlueKarana

asked on

Classic ASP: store and retrieve CLOB in Oracle

I'm storing a long string, about 17,000 chars, (base64 of an image) in a CLOB field in an Oracle database.

How do I retrieve the CLOB into a string, that is, the same base64 image string?

Currently I'm only getting 996 chars, then it cuts off.

*** all code is classic ASP ***

Code for storing CLOB:
BinRead = Request.BinaryRead(ByteCount)
Dim ImageStr
ImageStr= BinaryToString(BinRead)
    Set rsVisitReservation = Server.CreateObject ("ADODB.Command")
    rsVisitReservation.ActiveConnection = MM_NetBadgeOracle_STRING
    rsVisitReservation.CommandText = "UPDATE netbadge.VISITORRESERVATION SET PHOTOCLOB=? WHERE PASSID = " & PassID
   rsVisitReservation.Prepared = true
    rsVisitReservation.Parameters.Append rsVisitReservation.CreateParameter("param2", 201, 1, len(ImageStr), ImageStr) ' adLongVarChar
   Set rsVR = rsVisitReservation.Execute

Open in new window

Code for retrieving CLOB:
	ConnectStr = MM_NetBadgeOracle_STRING
	set rs = Server.CreateObject("ADODB.Recordset")
	SQL = "SELECT PHOTOCLOB FROM netbadge.visitorreservation WHERE passid =1443"
	Set rs = Server.CreateObject("adodb.recordset")
	rs.Open SQL, ConnectStr, 2, 3
	Response.BinaryWrite rs("PHOTOCLOB")

Open in new window

So, how do I get rs("PHOTOCLOB") into a string without truncation?

I've read about using ADO getchunks, but I haven't figured out how to do that successfully. It still truncates.

like so:

    ' Copy the string to a variable in chunks
	Dim varScan
	Dim VarChunk
	Dim lngOffset
	Dim varImgStr
    lngLogoSize = Len(rs("PHOTOCLOB"))
    lngOffset = 0
    Do While lngOffset < lngLogoSize
        varChunk = rs("PHOTOCLOB").GetChunk(conChunkSize)
        varImgStr = varImgStr & varChunk
        lngOffset = lngOffset + conChunkSize
   response.write "varImgStr = "& varImgStr

Open in new window

(The BinaryWrite only writes out 996 characters.)

Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BlueKarana


Yep. Sittin' here in my beehive and horn-rimmed glasses, tappin' out the classic ASP :P

For those who follow in my antidiluvian wake:

Dim ImgBuffer
Dim amount_read
Set OO4OSession = CreateObject("OracleInProcServer.XOraSession") 
Set NBDb = OO4OSession.OpenDatabase("[dbname]", "[username]/[password]", 0) 
Set visitorreservation = NBDb.CreateDynaset("select PHOTOCLOB from netbadge.visitorreservation WHERE passid =1443", 0) 
Set ScanImage = visitorreservation.Fields("PHOTOCLOB").Value 
amount_read = ScanImage.Read(ImgBuffer)

Open in new window

Thanks for the nudge, slightwv.