Stored Prodecure parameter does not exist error

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Ken McClain
Posts: 12
Joined: Fri 20 Jan 2006 17:44

Stored Prodecure parameter does not exist error

Post by Ken McClain » Thu 30 Mar 2006 19:37

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

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Fri 31 Mar 2006 08:50

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;

Post Reply