Page 1 of 1

Stored Prodecure parameter does not exist error

Posted: Thu 30 Mar 2006 19:37
by Ken McClain
I'm using SQL2005, and SDAC 3.70.1.25. I get an error when I attempt to assign a parameter to a Stored Procedure call using SDAC. I have verified that the parameter exists and can issue T-SQL using the same stored procedure and it works fine. Here is the stored procedure (partial):

CREATE PROCEDURE usp_UpdateADComputerTable
--Agruments
@DCName VARCHAR(128) -- Domain Controller
AS
.......

Delphi code;
procedure UpdateADComputerTable(Conn: TMSConnection; DCName: String);
const
cUpdateADComputerTable = 'usp_UpdateADComputerTable;1';
var
SP: TMSStoredProc;
begin
if (Conn = nil) then Exit;
SP := TMSStoredProc.Create(nil);
SP.Connection := Conn;
SP.StoredProcName := cUpdateADComputerTable;
SP.Params.ParamValues['DCName'] := DCName;
SP.FetchAll := TRUE;
try
RunStoredProc(SP);
SP.Free;
except on E: Exception do
begin
SP.Free;
raise Exception.CreateFmt(cDataIOException,[E.Message]);
end;
end; // try

This code fails on the line:
SP.Params.ParamValues['DCName'] := DCName;

with the exception:
'Parameter 'DCName' not found'

Any ideas on what might cause this? and how to fix it?

Thanks
Ken

Posted: Fri 31 Mar 2006 08:50
by Jackson
Before accessing stored procedure parameters verify that connection is open.
Otherwise MSStoredProc has no opportunity to get parameters information about stored procedure.
Just before setting stored procedure name specify something like this:
Conn.Connected := True;