QueryInterface for interface Borland.Vcl.IMalloc failed

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Posts: 3
Joined: Wed 05 Jul 2006 01:05

QueryInterface for interface Borland.Vcl.IMalloc failed

Post by benlaan » Fri 22 Sep 2006 06:39


I am getting the above error when running SDAC (VCL.NET) within a .NET Web Service (using Cassini Web Server). It is working correctly when only a single client call is established, but when a second concurrent call occurs, the error appears.

It is happening when attempting to open a new connection when one is already open. If I wait until it has finished, there is no problem..

As you can see from the stack trace below, I have encapsulated the call into a thread in order to apply the STA Apartment State (this cannot be applied to the service itself, thus I fork a new 'worker' thread to perform the work.

Can you please advise what this issue means, and what the solution might be.


Ben Laan


Version: SDAC for Delphi 2005.
CoreLab.Sdac, Version
CoreLab.Dac, Version


at CoreLab.Sdac.Units.OLEDBIntf.CoGetMalloc(Int32 dwMemContext, IMalloc& malloc)
at CoreLab.Sdac.TOLEDBConnection..ctor()
at CoreLab.Sdac.TMSConnection.GetOLEDBConnection()
at CoreLab.Sdac.TMSConnection.CreateIConnection()
at CoreLab.Dac.TCustomDAConnection.DoConnect()
at CoreLab.Dac.TCustomDAConnection.PerformConnect(Boolean Retry)
at CoreLab.Dac.TCustomDAConnection.SetConnected(Boolean Value)
at Borland.Vcl.TCustomConnection.Open()
at HSL.HAMBS.TSingleThreadedApartmentProcess.ThreadExecute() in ..\..\..\STACompartmentModel.pas:line 88

Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Wed 27 Sep 2006 15:06

We have reproduced the problem. The investigation of the problem is in progress. Unfortunately now we cannot give you any information. As soon as we solve the problem we'll let you know.

Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Thu 28 Sep 2006 15:46

We have thoroughly investigated the problem. The reason of the problem is that main and auxiliary threads work in different ThreadingModels. Main thread works in STAThread model but auxiliary in MTAThread model. IMAlloc interface that is used in OleDB and SDAC for memory management can not be used in the same application for different ThreadingModels. You can easly get to know current ThreadingModel analysing System.Threading.Thread.CurrentThread.ApartmentState.

To aviod this problem you should either set MTAThread model for main thread or avoid connecting to MSSQL from main thread.

Post Reply