🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #1821

Re: Access violation when deleting TADOQuery object

#1821
From: Dan Schmidt
Date: Tue, 10 Feb 2004 00:20
85 lines
3840 bytes
Found the reason for my memory exceptions and thought I'd post this for
anyone interested.

The problem is in the following code:

>    FField1->DataSet = FQuery;
>    FQuery->Fields->Add(FField1);

Assigning the DataSet property to FQuery and performing the Fields->Add()
method do almost the same thing. Both commands add the field information to
the Fields list, so I wound up with twice as many field reference pointers
as I needed. Therefore, when I perform the "delete FQuery" it tries to
delete each field reference twice. I needed to assign the DataSet property
so that I can access the FField1 object directly, so I eliminated the
Fields->Add() method call and my errors disappeared.

Also, assigning the DataSet property to NULL performs the same task as the
Fields->Remove() method.

Dan


"Dan Schmidt" <dan.schmidt@zedisolutions.com> wrote in message
news:402437cb$1@newsgroups.borland.com...
> I am using BCB6 Enterprise to create a web service (primarily using the
Web
> App Debugger for now). My web service must open a query to an Oracle table
> when the service starts up. My database connection start up code looks
like
> this:
>
>    // Create connection to Oracle database
>    FOracleConnection = new TADOConnection(Application);
>    FOracleConnection->LoginPrompt = false;
>
>    // Create main data access point
>    FQuery = new TADOQuery(FOracleConnection);
>
>    FOracleConnection->ConnectionString = WideString(...);
>    FOracleConnection->Open(...);
>    if (FOracleConnection->Connected)
>    {
>          FQuery->Connection = FOracleConnection;
>          FQuery->SQL->Text = "select ...";
>          FQuery->LockType = ltOptimistic;
>          FQuery->Prepared = true;
>          FQuery->Open();
>    } // if Connected
>
> Then my service does some stuff. Then it closes down:
>
>    FQuery->Close();
>    delete FQuery;
>
>    // Close Oracle database connection
>    FOracleConnection->Close();
>    delete FOracleConnection;
>
> If I allow the query to use dynamic fields, everything works just fine.
> Unfortunately, one of the fields in the query is a data type of
"DECIMAL(20,
> 0)", which none of the dynamic field types handle properly. So, I need to
> override the field types using my own defined persistent field objects.
>
>    FField1 = new TVariantField(FQuery);
>    FField1->FieldName = ...;
>    FField1->DataSet = FQuery;
>    FQuery->Fields->Add(FField1);
>
> And so on. Everything works fine until I try to delete the query object:
>
>    FQuery->Close();
>    FQuery->Fields->Remove(FField1);
>    delete FField1;
>    delete FQuery;
>
> The "delete FQuery;" statement generates an access violation at an address
> residing deep in the ADO source code. But, only when I use persistent
> fields.
>
> Does anyone know why this might be happening? Please help me!
>
> Dan
>
>
Technical Details
Message-ID: <40282400@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <402437cb$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10698b,6fc050c7c8a84663
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2004-02-09 16:39:39 PST
From: "Dan Schmidt" <dan.schmidt@zedisolutions.com>
Newsgroups: borland.public.cppbuilder.database.ado
References: <402437cb$1@newsgroups.borland.com>
Subject: Re: Access violation when deleting TADOQuery object
Date: Mon, 9 Feb 2004 17:20:35 -0700
Lines: 87
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 139.142.33.20
Message-ID: <40282400@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1076372480 139.142.33.20 (9 Feb 2004 16:21:20 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail