Solved

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

Posted on 2004-09-30
3
1,915 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 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

10 Experts available now in Live!

Get 1:1 Help Now