Parameter of stored procedure lost...

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
BigAl66
Posts: 11
Joined: Thu 10 Feb 2011 18:28
Location: Germany

Parameter of stored procedure lost...

Post by BigAl66 » Tue 05 Jul 2011 06:30

Hi,

I have a small problem:

I open a stored procedure using the TMSStoredProc object. Everything works fine. Only the parameters I specified where lost all the times. When I open the MSStoredProc Editor and specify my parameters I can access my data. When I close the editor and open it again, the parameters where set to "NULL".

Is it a bug?

Alex

AndreyZ

Post by AndreyZ » Tue 05 Jul 2011 09:42

Hello,

The point is that SDAC uses the @ symbol for working with parameters. To avoid both problems (here and http://www.devart.com/forums/viewtopic.php?t=21420), you should alter your procedure in the following way:

Code: Select all

ALTER PROCEDURE [dbo].[] 
@xxx INT 
AS 
BEGIN
...
After this, to access a parameter by name, you should use the following code:

Code: Select all

MSStoredProc.ParamByName('xxx').AsString := 'test';

BigAl66
Posts: 11
Joined: Thu 10 Feb 2011 18:28
Location: Germany

Post by BigAl66 » Tue 05 Jul 2011 09:59

Hi,

this do only partly work. The parameter will no not be lost anymore. But I can still not access it. I get always the error "Parameter 'xxx' not found'... :(

Any other idea?

Alex
AndreyZ wrote:Hello,

The point is that SDAC uses the @ symbol for working with parameters. To avoid both problems (here and http://www.devart.com/forums/viewtopic.php?t=21420), you should alter your procedure in the following way:

Code: Select all

ALTER PROCEDURE [dbo].[] 
@xxx INT 
AS 
BEGIN
...
After this, to access a parameter by name, you should use the following code:

Code: Select all

MSStoredProc.ParamByName('xxx').AsString := 'test';

AndreyZ

Post by AndreyZ » Tue 05 Jul 2011 11:35

Please try using the following code:

Code: Select all

MSStoredProc.StoredProcName := 'stor_proc_name';
MSStoredProc.PrepareSQL;
MSStoredProc.ParamByName('xxx').AsString := 'test';
MSStoredProc.Open;

BigAl66
Posts: 11
Joined: Thu 10 Feb 2011 18:28
Location: Germany

Post by BigAl66 » Tue 05 Jul 2011 12:07

Hi,

I found the problem. Changing the procedure in the SQL-Server will not update the call parameters in the TMSStoredProc object. After I changed to another stored procedure and go back to original one, the parameters look ok.

Thank you verry much for your fast and professional help!

Alex
AndreyZ wrote:Please try using the following code:

Code: Select all

MSStoredProc.StoredProcName := 'stor_proc_name';
MSStoredProc.PrepareSQL;
MSStoredProc.ParamByName('xxx').AsString := 'test';
MSStoredProc.Open;

AndreyZ

Post by AndreyZ » Tue 05 Jul 2011 12:33

It is good to see that this problem was solved. If any other questions come up, please contact us.

Post Reply