TMyDump.BackupToFile Causes access violation when closing form

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
GaryShelton
Posts: 5
Joined: Tue 22 Jan 2019 06:29

TMyDump.BackupToFile Causes access violation when closing form

Post by GaryShelton » Mon 18 Feb 2019 17:35

I have the following code. If I comment out the call to BackupToFile everything works fine, otherwise I get an access violation when closing the frmBackup. Tried many different solutions from posting on stackOverflow but no joy. Any help?

procedure TfrmMain.CmdBackupExecute(Sender: TObject);
var
SaveDialog: TSaveDialog;
QRYString: String;
frmBackup: TfrmBackup;
Password: String;
BackupPassword: String;
MasterPassword: String;
CurrentFrame: TFrameType;
OldUser: String;
OldPassword: String;
begin
dmVintage.tblSettings.Open;
BackupPassword:= dmVintage.tblSettings.FieldByName('BackupRestorePWord').AsString;
MasterPassword:= dmVintage.tblSettings.FieldByName('MasterPWord').AsString;
InputPassword('Enter Backup Password', Password);
if Password = BackupPassword then
try
try
//close current frame and change to root
CurrentFrame:= FrameManager.CurrentFrameType;
FrameManager.Clear;
dmVintage.connMain.LoginPrompt:= False;
OldUser:= dmVintage.connMain.Username;
OldPassword:= dmVintage.connMain.Password;
dmVintage.connMain.Connected:= False;
dmVintage.connMain.Username:= 'root';
dmVintage.connMain.Password:= MasterPassword;
dmVintage.connMain.Connect;
SaveDialog:= TsaveDialog.Create(nil);
SaveDialog.Filter := 'SQL file|*.sql';
SaveDialog.DefaultExt:= '.sql';
SaveDialog.FileName:= 'VintageData';
if SaveDialog.Execute then
begin
frmBackup:= TfrmBackup.Create(nil);
frmBackup.Show;
frmBackup.mdVintage.BackupToFile(AddTimestampToFilename(SaveDialog.FileName), QryString);
dlgI('Backup Successful');
frmBackup.Close;
frmBackup.Release;
end;
Except on E: Exception do
dlgW2('TfrmMain.CmdBackupExecute', E.Message);
end;
finally
SaveDialog.Free;
//reset connection and load old frame
dmVintage.connMain.Connected:= False;
dmVintage.connMain.Username:= OldUser;
dmVintage.connMain.Password:= OldPassword;
dmVintage.connMain.Connect;
dmVintage.connMain.LoginPrompt:= True;

FrameManager.LoadFrame(CurrentFrame);
end
else
dlgE('Invalid Backup Password');
end;

function TfrmMain.AddTimestampToFilename(Value: String): String;
var
Extension: String;
FileName: String;
FormattedDataTime: String;
begin
Extension:= ExtractFileExt(Value);
FileName:= ChangeFileExt(Value, '');
DateTimeToString(FormattedDataTime, 'yyyymmdd_hhmm', Now);
FileName:= FileName + '_' + FormattedDataTime;
Result:= ChangeFileExt(FileName, Extension);
end;

unit uBackup;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, uDataVintage, DADump, MyDump,
Vcl.ComCtrls, Vcl.StdCtrls;

type
TfrmBackup = class(TForm)
mdVintage: TMyDump;
lblBackingUpTable: TLabel;
lblTable: TLabel;
Label3: TLabel;
pbBackup: TProgressBar;
procedure mdVintageBackupProgress(Sender: TObject; ObjectName: string;
ObjectNum, ObjectCount, Percent: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;



implementation

{$R *.dfm}

procedure TfrmBackup.mdVintageBackupProgress(Sender: TObject;
ObjectName: string; ObjectNum, ObjectCount, Percent: Integer);
begin
if lblTable.Caption <> ObjectName then
begin
lblTable.Caption:= ObjectName;
lblTable.Repaint;
end;
pbBackup.Position:= Percent;
end;

end.

GaryShelton
Posts: 5
Joined: Tue 22 Jan 2019 06:29

Re: TMyDump.BackupToFile Causes access violation when closing form

Post by GaryShelton » Mon 18 Feb 2019 17:41

Forgot to mention, TDump does work. SQL file is created with all tables and views as well as the current data 9000+ lines. Also it does work when using the file to restore, just seems the process never actually quits.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: TMyDump.BackupToFile Causes access violation when closing form

Post by ViktorV » Tue 19 Feb 2019 10:08

In order for us to be able to give you a detailed answer, we need to have a sample demonstrating the specified behavior. Therefore, please compose a full sample demonstrating the described behavior and send it to us using the contact form https://devart.com/company/contactform.html including scripts for creating and filling database objects.

GaryShelton
Posts: 5
Joined: Tue 22 Jan 2019 06:29

Re: TMyDump.BackupToFile Causes access violation when closing form

Post by GaryShelton » Tue 19 Feb 2019 18:14

I found the problem. I open the settings table and did not close it. That brings up a question. Do all users need to close all connections(Open tables really) in order to backup or is it just the client that is doing the backup?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: TMyDump.BackupToFile Causes access violation when closing form

Post by ViktorV » Thu 21 Feb 2019 07:33

If possible, please create a small example demonstrating the issue. It will help us to provide you with the quickest and the most exact response.

Post Reply