Article View: borland.public.cppbuilder.database.ado
Article #1236Re: Error opening an ADOConnection
From: Renato
Date: Wed, 29 Sep 2004 19:19
Date: Wed, 29 Sep 2004 19:19
109 lines
4944 bytes
4944 bytes
Hi Viatcheslav,
your idea works! Thank you
I didn�t know Adoconnection works similar to TDatabase. the code if
you�re interested became the following:
this->ADOConnection1->Close();
this->ADOConnection1->Open();
this->ADOConnection1->BeginTrans();
str_SQL = "insert into projeto_abrangencia (desc_projabrang,
id_abrang) ";
str_SQL +=" select '" + str_Localidade + "', a.id_abrang ";
str_SQL +=" from abrangencia a ";
str_SQL +=" where a.tipo_abrang = '" + str_Abrang + "'";
this->ADOQInsProjPesq->Close();
this->ADOQInsProjPesq->SQL->Clear();
this->ADOQInsProjPesq->SQL->Add(str_SQL);
try {
this->ADOQInsProjPesq->ExecSQL();
this->ADOConnection1->CommitTrans();
this->ADOQInsProjPesq->Close();
} catch (...) {
this->ADOConnection1->RollbackTrans();
this->ADOQInsProjPesq->Close();
ShowMessage ("Erro ao gravar '" + str_Localidade + "' no banco");
}
this->ADOConnection1->Close();
Thank you again.
Viatcheslav V. Vassiliev wrote:
> It seems that this->ADOQInsProjPesq or this->ADOQInsProjPesq->Connection is
> NULL - create new TADOConnection if this is the case or set ConnectionString
> property. Use existing methods of TADOConnection when they are available,
> such as for start/end transation.
>
> //------------------------------------------
> Regards,
> Vassiliev V. V.
> http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
> ADO.Net
> http://www.oledbdirect.com - The fastest way to access MS SQL Server,
> MS Jet (Access) and Interbase (through OLEDB)
>
> "Renato" <rc-freitas@uol.com.br> ???????/???????? ? ???????? ?????????:
> news:4157819d$1@newsgroups.borland.com...
>
>>Hi!
>>
>>I�m using ADO+MS Access. i�m trying to open a connection but I got this
>>message:
>>
>>Project PCeale.exe raised exception class EAccessViolation with message
>>'Access violation at address 405B92BA in module 'VCDLDB50.BPL'. Read of
>>address 00000000'. Process stopped. Use Step or Run to continue.
>>
>>I used CodeGuard to analyse the code and I get the warning when error
>>happens:
>>
>>Method called on invalid object
>>Attempt to access 216 bytes at 0x00000000.
>>0xEEEEEEEE
>>Adodb::TADOConnection::Open()
>>TProjPesqForm::BtnGravaProjPesqClick(const System::TObject *)
>>0x4006B958
>>0x40047E41
>>0x4006E4A8
>>0x4006DF7B
>>
>>The code where it happens is the following (ADOQInsProjPesq is an
>>ADOQuery with connectionString = Provider=Microsoft.Jet.OLEDB.4.0;Data
>>Source=C:\renato\sistemas\ceale\ceale.mdb;Mode=ReadWrite|Share Deny
>>None;Persist Security Info=False):
>>
>> AnsiString str_SQL = "";
>> AnsiString str_IDProjAbrang = "0";
>> //Abrangencia Beg.
>>
>> this->ADOQInsProjPesq->Connection->Open(); <<== LOCATION OF ERROR !
>>
>> this->ADOQInsProjPesq->Connection->BeginTrans();
>>
>> str_SQL = "insert into projeto_abrangencia (desc_projabrang,
>>id_abrang) ";
>> str_SQL +=" select '" + str_Localidade + "', abrangencia.id_abrang ";
>> str_SQL +=" from projeto_abrangencia pa, abrangencia a ";
>> str_SQL +=" where pa.id_abrang = a.id_abrang ";
>> str_SQL +=" and a.tipo_abrang = '" + str_Abrang + "'";
>>
>> this->ADOQInsProjPesq->Close();
>> this->ADOQInsProjPesq->SQL->Clear();
>> this->ADOQInsProjPesq->SQL->Add(str_SQL);
>>
>> try {
>> this->ADOQInsProjPesq->ExecSQL();
>> this->ADOQInsProjPesq->Connection->CommitTrans();
>> } catch (...) {
>> this->ADOQInsProjPesq->Connection->RollbackTrans();
>> ShowMessage ("Erro ao gravar '" + str_Localidade + "' no banco");
>> return; //interrupcao da gravacao
>> }
>> this->ADOQInsProjPesq->Close();
>>
>>I�d like to know what i�m doing wrong... thank you.
>
>
>
Technical Details
Message-ID:
<415b09a2@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!solnet.ch!solnet.ch!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4157819d$1@newsgroups.borland.com> <4157b1be$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,822c685322161d3a X-Google-Attributes: gid10698b,public X-Google-Language: ENGLISH,ASCII Date: Wed, 29 Sep 2004 16:19:23 -0300 From: Renato <rc-freitas@uol.com.br> User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7) Gecko/20040608 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.database.ado Subject: Re: Error opening an ADOConnection References: <4157819d$1@newsgroups.borland.com> <4157b1be$1@newsgroups.borland.com> In-Reply-To: <4157b1be$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit NNTP-Posting-Host: 201.8.165.91 Message-ID: <415b09a2@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1096485282 201.8.165.91 (29 Sep 2004 12:14:42 -0700) Lines: 109 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!solnet.ch!solnet.ch!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail