Page 1 of 1

How to load Varbinary data from a stored procedure output parameter

Posted: Wed 04 Jul 2007 09:27
by bledazemi
I am trying to use SDAC TMSStoredProc to run a SQL stored procedure which returns in a varbinary output parameter which contains the image of a person. I would really appreciate if someone would take some time to help me on this. I have given below the full Procedure definition in SQL table as well as the Delphi code that i have written.

The SQL procedure is defined in a SQL 2000 database as below:
------------------------------------------------------------------------------
CREATE PROCEDURE Get_Inmate_Photo2
@PersonID Varchar(12),
@Photo varbinary(16) Output,
@PhotoSize integer Output,
AS

SELECT @Photo=TEXTPTR(Photograph), @PhotoSize=DataLength(Photograph)
FROM person
WHERE person.PersonID=@PersonID
READTEXT person.Photograph @Photo 0 @PhotoSize

GO
--------------------------------------------------------------

The person table is contains to fields and can be recreated as below:

Create table person
(
PersonID varchar(12) Primary Key,
Photograph Image
);


This is how i am trying to get the data out:

procedure TForm2.Button1Click(Sender: TObject);
var
ms:TMemoryStream;
size:integer;
param:TMSParam;
pData:pByte;
begin
//This runs fine (I have setup connection and stored procedure name)
MSStoredProc1.Execute;

//This also returns the correct output value
size:=MSStoredProc1.ParamByName('PhotoSize').AsInteger;

//Here i am trying to get the data out of varbinary output parameter 'Photo'
param:=MSStoredProc1.ParamByName('Photo');
GetMem(pData,size);
try
//The line below throws an exception
//for some reason param.fParam is nil
param.GetData(pData);

finally
FreeMem(pData);
end;
end;

Many Thanks in Advance

Posted: Thu 05 Jul 2007 15:02
by Antaeus
I could not reproduce the problem.
Please send me a complete small sample at evgeniyD*crlab*com to demonstrate it, including script to create and fill table.

Also supply me the following information:
- exact version of SDAC. You can see it in the About sheet of TMSConnection Editor;
- exact version of your IDE (including personality name for Delphi 2005, and BDS 2006).