Jump to content
dlucic

DataSnap Could not convert variant of type (Array Byte) into type (Integer)

Recommended Posts

I have simple DataSnap server application with connection to MS SQL Server and also simple client application. On the server side I have TFDConnection object to connect to MS SQL Server. I also have TFDQuery with simple sql "insert into slika_test (slika) values (:slika)". Param slika is for image datatype in table test_slika. This is properties of Param slika of TFDQuery object

 

image.png.29bed49ec8d587568bf9ce6aed950685.png

 

Of course, there is DataSetProvider object

 

On the client side I have TSQLConnection and DSProviderConnection object's. I connect to DataSnap server application with them. There is also TClientDataSet object

 

image.png.8c88bd14d0116137a7acb8a8a34c46a2.png

 

This is code for click on Button

 

image.thumb.png.1fd4485b31b0073dc136b7b730c54036.png

 

I load image from Image1 object on the form into MemoryStream. Than I put that MemoryStream in Param of ClientDataSet object and execute. 

 

When I do that for the first time everything goes well. Data is stored in MS SQL table. But when I click it another time and same code executes I receive this error on the server application

 

image.thumb.png.a6d0e855499ce2bdd18a86b985e02e6c.png

 

Any body knows what is the problem?

 

 

 

 

 

 

image.png

Share this post


Link to post
3 hours ago, dlucic said:

image.thumb.png.1fd4485b31b0073dc136b7b730c54036.png

 

image.png

You are not resetting ms.Position=0 before calling Param.LoadFromStream().

You are also leaking the TMemoryStream.

Share this post


Link to post
16 hours ago, Remy Lebeau said:

You are not resetting ms.Position=0 before calling Param.LoadFromStream().

You are also leaking the TMemoryStream.

Thank you bu that is not my problem. I changed code as you tell me but I still have this massage
 

image.thumb.png.f7ede0c00a8fdf1c44c87f6886c187ed.png

 

image.thumb.png.7483237f35153fd40fa60f076fc58349.png

Share this post


Link to post

Thanks again. If you wish I can send you compleate code for both applications. That is small peace of code for each of them. But you need a small MS SQL Database with one table with just to columns

Share this post


Link to post

What I see, that you want to put some image into SQL "insert" command.

If I try to save some blob, I every time use dataset field and call TClientdataset.ApplyUpdates.

Example:

//you wan to create new record therefore append

dodajslikujds.append;

try

  dodajslikujds.Fieldsbyname('here put correct fieldname').loadFromstream(ms);

 dodajslikujds.Post;
  var  I := dodajslikujds.ApplyUpdates(0);
   if (I <> 0) then
   begin
      raise Exception.Create('Data was not saved!');
    end; {if}

except

  dodajslikujds.Cancelupdates;

  raise;

end;

Share this post


Link to post
1 hour ago, Jirka52 said:

What I see, that you want to put some image into SQL "insert" command.

If I try to save some blob, I every time use dataset field and call TClientdataset.ApplyUpdates.

Example:

//you wan to create new record therefore append

dodajslikujds.append;

try

  dodajslikujds.Fieldsbyname('here put correct fieldname').loadFromstream(ms);

 dodajslikujds.Post;
  var  I := dodajslikujds.ApplyUpdates(0);
   if (I <> 0) then
   begin
      raise Exception.Create('Data was not saved!');
    end; {if}

except

  dodajslikujds.Cancelupdates;

  raise;

end;

Thank you, it works fine now.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×