Re: OLE error 80040E21 reading BIGINT using AsFloat



"Dan Cumpian" <ir000387@xxxxxxxxxxxxxx> wrote
We have a program that connects to a SQL Server database. There are
several BIGINT fields in the database. To retrieve data from one of the
fields, we use the following code:
function GetBytesAsMB: Real;
begin
Result := DMMSSQL.QryServers.FieldByName
('BytesPerLimit').AsFloat/1048576;
end;

Dan, I hope that I fixed the above correctly.

Now, for 90% of our customers, this works just fine. We can't
retrieve using "AsInteger" because the number can easily be
larger than the number supported by the Integer type.
However, a few installations return the following error:
exception class : EOleException
exception message : OLE error 80040E21.
The exception is raised at line 4199 in ADODB.pas:
DataConvert(Field, @C, Buffer, True) else

I am not familiar with ADO, but I assume that BIGINT is 64-bits
signed integer, and that ADO does not allow reading as such.

Trying to convert such a 64-bit signed integer into a "double"
(which is what a type "real" usually is defined as) is problematic.
The double has only 52 or 53 significant bits not counting the
sign and exponent. Further, if ADO does not recognize the
BIGINT, then I would suspect that there could be other
problems with the conversion.

The conversion to AsFloat can also fail if the FPU's control
word (CW) is set incorrectly by Windows or some other
code within your program. You can check this by examining
the control word before the point of the AsFloat with a
Get8087CW call. It should return $1332 (that's hex) or
$1372.

As far as a work-a-round, can you bypass the AsInteger
and AsFloat and read the 64-bits out of the record buffer
as bytes? If so, then you could convert the 8-bytes directly
into 8-byte buffer and from there directly into an Int64
integer type.

HTH, JohnH



.