user1769184
user1769184

Reputation: 1621

Parameter of stored procedure not found

I use the following code to call my stored procedure using TADOStoredProc type

MySP.Connection := aConnection;
MySP.ProcedureName := 'dbo.UpdateErrors';
MySP.Parameters.ParamByName('@Error_Number').value := -1;
MySP.Parameters.ParamByName('@NewError_Name').value := 'errorM1';
MySP.Parameters.Refresh;

MySP.ExecProc;

The parameter @Error_Number is part of the stored procedure UpdateErrors using SQL Server Management Studio, I add snip image for confirmation

enter image description here

but I can't understand why I get an error

Upvotes: 0

Views: 1853

Answers (2)

NizamUlMulk
NizamUlMulk

Reputation: 386

The most common case is: the user connected to database hasn´t permissions for execute the procedure. You must grant it

Upvotes: 0

Jasper Schellingerhout
Jasper Schellingerhout

Reputation: 1090

Simply use a TADOCommand

  MyCommand.Connection := aConnection;
  MyCommand.CommandText := 'EXEC dbo.UpdateErrors :Er, :Na'; //you can call the params what you want
  MyCommand.Parameters[0].value := -1; //Or you can do ParamByNname and use Er and Na (or whatever you called your params) instead of indices
  MyCommand.Parameters[1].value := 'errorM1';
  MyCommand.Execute;

If you want to fix your code

Do

 ErParam := MySP.Parameter.Add;
 ErParam.Name := '@Error_Number';
 ErParam.DataType := ftInteger; //put your correct type here
 ErParam.Direction := pdInput; //set your direction for the param

etc. Lots more work... do the first way with ADOCommands

Upvotes: 2

Related Questions