Page 1 of 1

QueryInterface for interface Borland.Vcl.IMalloc failed

Posted: Fri 22 Sep 2006 06:39
by benlaan
Hi

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.

Thanks

Ben Laan

--

Version: SDAC 3.70.3.29 for Delphi 2005.
CoreLab.Sdac, Version 3.70.3.3029
CoreLab.Dac, Version 5.70.1.3033

--

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

Posted: Wed 27 Sep 2006 15:06
by Antaeus
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.

Posted: Thu 28 Sep 2006 15:46
by Antaeus
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.