Solved

Passing a BLOB as a  longvarbinary parameter to a stored proc ?

Posted on 2004-09-30
3
1,937 Views
Last Modified: 2013-12-25
Hi,

I'm having problems passing a byte array to a stored proc as a longvarbinary.
The sample code that follows throws an error:
"Application uses a value of the wrong type for the current operation."
when I attempt to append a chunk.

Any ideas?


Public Function AddLongBin() As Boolean

    Dim cmd As New ADODB.Command
    Dim prmID As ADODB.Parameter
    Dim prmBin As ADODB.Parameter
    Dim aBin() As Byte

   
On Error GoTo ErrHandler

    cmd.ActiveConnection = cnDatabase
    cmd.CommandText = "AddLongBin"
    cmd.CommandType = adCmdStoredProc
   
    ReDim aBin(100) As Byte
   
    Set prmBin = cmd.CreateParameter("Bin", adLongVarBinary, adParamInput, 100)
    cmd.Parameters.Append prmBin
   
    prmBin.Attributes = adFldLong
    prmBin.AppendChunk aBin
   
    cmd.Execute

ErrHandler:
    If Err.Number <> 0 Then
        MsgBox Err.Description
        Err.Clear
    End If
   

End Function
0
Comment
Question by:aregan
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
Alan Warren earned 20 total points
ID: 12234488
Heres one I use maybe it will help you.
The thing I see as different is the defined size for you blob parameter.
http://www.able-consulting.com/ADODataTypeEnum.htm



  with cmd
    ' zips are stored in another table so use different stored query
    If sFileExtension = "zip" Then
        .CommandText = "spJetPackBlob_zip"
    Else
      .CommandText = "spJetPackBlob"
    End If      
    .CommandType = adCmdStoredProc        
      .Parameters.Append .CreateParameter("pFileName", adVarChar, adParamInput, 255, sFileName)
      .Parameters.Append .CreateParameter("pFileType", adVarChar, adParamInput, 255, sFileType)
      .Parameters.Append .CreateParameter("pDateCreated", adDBTimeStamp, adParamInput, 8, dDateCreated)
      .Parameters.Append .CreateParameter("pDateLastAccessed", adDBTimeStamp, adParamInput, 8, dDateLastAccessed)
      .Parameters.Append .CreateParameter("pFileSize", adInteger, adParamInput, 4, lFileSize)
      .Parameters.Append .CreateParameter("pFileExtension", adVarChar, adParamInput, 255, sFileExtension)
      .Parameters.Append .CreateParameter("pFileBinary", adLongVarBinary, adParamInput,2147483647, oFileBinary)
    Set .ActiveConnection = cn
    .Execute
  end with


Might find some usefull information and samples relating to using blobs here too:
http://www26.brinkster.com/alzowze/blobs.asp


Alan
0
 

Author Comment

by:aregan
ID: 12235378
Thanks Alan

Just figured this out last nite. Your right - it was the paremeter length that was throwing it out.

Alan.
0
 
LVL 26

Expert Comment

by:Alan Warren
ID: 12235399
Thanks Alan,

you know you can actually set the param size to the len(oFileBinary)

.Parameters.Append .CreateParameter("pFileBinary", adLongVarBinary, adParamInput,len(oFileBinary), oFileBinary)

Alan :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 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

14 Experts available now in Live!

Get 1:1 Help Now