Access violation when using TZStoredProc

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
markd_mms
Fresh Boarder
Fresh Boarder
Posts: 8
Joined: 30.09.2005, 02:08

Access violation when using TZStoredProc

Post by markd_mms »

I'm using Firebird embedded 1.5.2.4731 and I can't seem to use TZStoredProc - I always get an exception in the destructor of the TZConnection if I try to use them. I don't have any problem with TZQuery.

Code is as follows...
[syntax="c"]
std::auto_ptr<TZStoredProc> qryEditRule(new TZStoredProc(NULL));
//std::auto_ptr<TZReadOnlyQuery> qryEditRule(new TZReadOnlyQuery(NULL));
qryEditRule->Connection = frmData->Database;
qryEditRule->StoredProcName = "CHANGE_FTP_RULE_SP";

/*qryEditRule->SQL->Add("UPDATE FTP SET \"NAME\" = :NAME,");
qryEditRule->SQL->Add("\"ENABLED\" = :ENABLED, \"TYPE\" = :TYPE,");
qryEditRule->SQL->Add("\"SERVER\" = :SERVER, \"FILES\" = :FILES,");
qryEditRule->SQL->Add("\"REMOTEPATH\" = :REMOTEPATH,");
qryEditRule->SQL->Add("\"DELETEFILES\" = :DELETEFILES,");
qryEditRule->SQL->Add("\"SAVEFILES\" = :SAVEFILES, \"SAVEPATHS\" = :SAVEPATHS,");
qryEditRule->SQL->Add("\"ZIPFILES\" = :ZIPFILES,");
qryEditRule->SQL->Add("\"ZIPFILENAME\" = :ZIPFILENAME,");
qryEditRule->SQL->Add("\"INTERVAL\" = :INTERVAL,");
qryEditRule->SQL->Add("\"CHECKTIMES\" = :CHECKTIMES,");
qryEditRule->SQL->Add("\"TRAVERSEDIRS\" = :TRAVERSEDIRS,");
qryEditRule->SQL->Add("\"SHOWALERT\" = :SHOWALERT");
qryEditRule->SQL->Add("WHERE \"ID\" = :ID");*/

qryEditRule->ParamByName("NAME")->AsString = GetName();
qryEditRule->ParamByName("ENABLED")->AsBoolean = GetEnabled();
qryEditRule->ParamByName("TYPE")->AsInteger = (int)GetType();
qryEditRule->ParamByName("SERVER")->AsInteger = GetServer();
qryEditRule->ParamByName("FILES")->AsString = Files->CommaText;
qryEditRule->ParamByName("DELETEFILES")->AsBoolean = GetDeleteFiles();
qryEditRule->ParamByName("REMOTEPATH")->AsString = GetRemotePath();
qryEditRule->ParamByName("SAVEFILES")->AsBoolean = GetSaveFiles();
qryEditRule->ParamByName("SAVEPATHS")->AsString = SavePaths->CommaText;
qryEditRule->ParamByName("ZIPFILES")->AsBoolean = GetZipFiles();
qryEditRule->ParamByName("ZIPFILENAME")->AsString = GetZipFileName();
qryEditRule->ParamByName("INTERVAL")->AsInteger = GetInterval();
qryEditRule->ParamByName("CHECKTIMES")->AsString = CheckTimes->CommaText;
qryEditRule->ParamByName("TRAVERSEDIRS")->AsBoolean = GetTraverseDirs();
qryEditRule->ParamByName("SHOWALERT")->AsBoolean = GetShowAlert();
qryEditRule->ParamByName("ID")->AsInteger = GetID();

try {
//qryEditRule->ExecSQL();
qryEditRule->ExecProc();
qryEditRule->Connection->Commit();
} catch (Exception &E) {
ShowMessage(E.Message);
qryEditRule->Connection->Rollback();
return;
}
[/syntax]

If this code is ran using TZStoredProc then when I closed the program and the TZConnection is destroyed I get an access violation in fbclient.dll. I've attached a stack trace of the exception.

I though it might be becuase I was instantiating it programatically but even if I drop the component onto a form and use that, the same thing happens. And using TZQuery doesn't create the same problem. Using normal pointers doesn't make a difference either.

Any ideas what could be going wrong?

I'm using BCB 6 update 4 and ZeosLib 6.5.1 alpha.

TIA

EDIT:
I also get an invalid staement handle exception, although it doesn't always happen. Stack trace for that is attached as well
You do not have the required permissions to view the files attached to this post.
User avatar
fduenas
Zeos Dev Team
Zeos Dev Team
Posts: 132
Joined: 26.08.2005, 08:12
Location: Cancún

Post by fduenas »

Hi do you use the latest CVS version?
markd_mms
Fresh Boarder
Fresh Boarder
Posts: 8
Joined: 30.09.2005, 02:08

Post by markd_mms »

I tried the latest CVS version but now I can't even connect. I keep on getting unvailable database and it tells me it can't find interbase.msg. The 6.5.1 non-CVS version would complain it was missing firebird.msg so maybe it's using the wrong protocol, although I set it to firebird-1.5.
markd_mms
Fresh Boarder
Fresh Boarder
Posts: 8
Joined: 30.09.2005, 02:08

Post by markd_mms »

WINDOWS_DLL_LOCATION in ZPlainFirebird15.pas was set to gds32.dll so I just changed it to fbclient.dll and re-compiled

It still crashes with the CVS version.
markd_mms
Fresh Boarder
Fresh Boarder
Posts: 8
Joined: 30.09.2005, 02:08

Post by markd_mms »

I'm still trying to figure this out and I've run into something I don't understand

Code: Select all

procedure TZAbstractRODataset.SetConnection(Value: TZConnection);
begin
  if FConnection <> Value then
  begin
    if Active then Close;
    Statement := nil;
    if FConnection <> nil then
      FConnection.UnregisterDataSet(Self);
    FConnection := Value;
    if FConnection <> nil then
      FConnection.RegisterDataSet(Self);
  end;
end;
In the destructor for TZAbstractRODataset it calls SetConnection(nil) which I would expect would then call TZConnection.UnregisterDataSet so that when the TZConnection is destroyed it doesn't try and delete something that has already been destroyed.

Shouldn't SetConnection(nil) call TZConnection.UnregisterDataSet? Something like...

Code: Select all

procedure TZAbstractRODataset.SetConnection(Value: TZConnection);
begin
  if FConnection <> Value then
  begin
    if Active then Close;
    Statement := nil;
    if Value = nil then
      FConnection.UnregisterDataSet(Self);
    FConnection := Value;
    if FConnection <> nil then
      FConnection.RegisterDataSet(Self);
  end;
end;
TIA
Post Reply