Using ADO to send image data to a SQL 2000 stored procedure

M

Mark Sherwood

When running the code the following error is displayed when setting either
the value or appendchunk for the file data.



Run-time error '3421':

Application uses a value of the wrong type for the current operation.



The code is from VBA using ADO 2.7 connecting to a stored procedure in SQL
Server 2000 that has the parameter defined as an Image data type.

How can the image data type be used in ADO to send file data to a stored
procedure?



' get binary data

Set aStream = New ADODB.Stream

aStream.Charset = "ascii"

aStream.Type = adTypeBinary

aStream.Open

aStream.LoadFromFile "C:\aSample.pdf"

aStream.Position = 0



Set prm = New ADODB.Parameter

prm.Name = "@DocFileSize"

prm.Type = adInteger

prm.Size = 3

prm.Direction = adParamInput

prm.Value = aStream.Size

com.Parameters.Append prm

Set prm = Nothing





Set prm = New ADODB.Parameter

prm.Name = "@DocFileData"

prm.Type = adLongVarBinary

prm.Size = 16

prm.Direction = adParamInput

prm.Value = aStream.Read

'prm.AppendChunk aStream.Read



com.Parameters.Append prm

Set prm = Nothing



' close file

aStream.Close

Set aStream = Nothing
 
S

Steven Parsons [MSFT]

Hi Mark -

This is Steven from Microsoft Access Technical Support replying to your
newsgroup post. I understand that you are receiving run-time error 3421
when trying to access a stored procedure via ADO. Of the sample code that
you provided, I am not sure which line of code is causing this error.
Therefore, you may want to take a look at the following webpage to see if
it will provide you with a resolution:

PRB: Error Message 3421 Passing a BLOB Argument to a Stored Procedure
http://support.microsoft.com/default.aspx?scid=KB;EN-US;190450

Please let me know whether this page resolves the problem or if you need
further assistance.

Sincerely,
Steven Parsons [MSFT]
Microsoft Access Product Support Services
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! (http://www.microsoft.com/security)
 
Top