Page 1 of 1

Memory Leak with SDAC 4.80 when using output params

Posted: Wed 16 Nov 2011 13:09
by Pegasys
Hi,

I have a Delphi 2007 application using SDAC 4.80.0.60 with SQL Server 2008 SP3 Standard Edition.

Everything is working well, but there's a memory leak when using TMSQuery with output parameters to get the id for the recently created entry.

Here's the delpi code:

Code: Select all

Query := TMSQuery.Create(nil);
  try
    Query.Connection := Connection;
    Query.SQL.Add('Insert into Test (Name, Timestamp) values (:NAME, :Timestamp)');
    Query.ParamByName('Name').asString := 'Versuch';
    Query.ParamByName('Timestamp').AsDateTime := now;
    Query.SQL.Add('; SET :PK = SCOPE_IDENTITY() ');
    Query.ParamByName('PK').ParamType := ptInputOutput;

    Query.Execute;

    id := Query.ParamByName('PK').AsInteger;
    label1.caption := 'ID : ' + IntToStr(id);
  finally
    Query.Close;
    FreeAndNil(Query);
  end;
The table Test is defined like this:

Code: Select all

CREATE TABLE [dbo].[Test](
	[ID] [int] IDENTITY(1,1) NOT NULL,
	[Name] [nvarchar](50) NOT NULL,
	[Timestamp] [datetime] NOT NULL,
 CONSTRAINT [PK_Test] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
For each insert there's a leak with the size of 32 bytes.

Edit:
Problem solved by adding this line:

Code: Select all

Query.ParamByName('PK').DataType := ftInteger;

Posted: Mon 21 Nov 2011 10:35
by AndreyZ
Hello,

It's not a memory leak. When the data type of a parameter is unknown, SDAC allocates memory for it. Such SDAC behaviour is correct.