Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 12 total
Thread Error using RESTORE DATABASE clause.
Tue, Jul 23 2013 10:02 AMPermanent Link

Abdulaziz Al-Jasser

Hi,

I searched the forums before posting this thread but could not find the solution.  I am trying to restore a database backup but get this #300 exclusive luck error!!!  I am not running my application from IDE (IDE is closed) and DBManager is closed and have one session only.  Here is my code:

Function RestoreDatabase(sBackupFileName : string) : Boolean;
var
        sSQL : String;
begin
        try
           EDBDatabase1.Close;

           CreateStore('Backups',ExtractFileDir(sBackupFileName));

           sSQL := 'RESTORE DATABASE %s FROM "%s" IN STORE "Backups" INCLUDE CATALOG';
           sSQL := Format(sSQL,[rSystemData.DatabaseName,ExtractFileName(sBackupFileName)]);

           EDBSession1.Execute(sSQL);

           DropStore('Backups');

           Result := True;
        except
           Result := False;
        end;
end;


I am using version 2.11 B3 with XE2.
Regards,
Abdulaziz Jasser
Tue, Jul 23 2013 10:18 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Abdulaziz


Swop these two lines

          EDBDatabase1.Close;

           CreateStore('Backups',ExtractFileDir(sBackupFileName));


round. The first one closes the database and the second one will open it to create the store so the backup can't get exclusive access.

Roy Lambert [Team Elevate]
Tue, Jul 23 2013 3:21 PMPermanent Link

Abdulaziz Al-Jasser

Roy,

I made the changes not the function is:

Function RestoreDatabase(sBackupFileName : string) : Boolean;
var
        sSQL : String;
begin
        try
           CreateStore('Backups',ExtractFileDir(sBackupFileName));

           EDBDatabase1.Close;

           sSQL := 'RESTORE DATABASE %s FROM "%s" IN STORE "Backups" INCLUDE CATALOG';
           sSQL := Format(sSQL,[rSystemData.DatabaseName,ExtractFileName(sBackupFileName)]);

           EDBSession1.Execute(sSQL);

           DropStore('Backups');

           Result := True;
        except
           Result := False;
        end;
end;

Now I get this error:

"The system cannot the file specified."

Regards,
Abdulaziz Jasser
Tue, Jul 23 2013 3:22 PMPermanent Link

Abdulaziz Al-Jasser

Roy,

I made the changes to the function:

Function RestoreDatabase(sBackupFileName : string) : Boolean;
var
       sSQL : String;
begin
       try
          CreateStore('Backups',ExtractFileDir(sBackupFileName));

          EDBDatabase1.Close;

          sSQL := 'RESTORE DATABASE %s FROM "%s" IN STORE "Backups" INCLUDE CATALOG';
          sSQL := Format(sSQL,[rSystemData.DatabaseName,ExtractFileName(sBackupFileName)]);

          EDBSession1.Execute(sSQL);

          DropStore('Backups');

          Result := True;
       except
          Result := False;
       end;
end;

Now I get this error:

"The system cannot the file specified."
Regards,
Abdulaziz Jasser
Wed, Jul 24 2013 3:21 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Abdulaziz


Sorry, I can't help you there. You'll have to set a breakpoint and track things through to see what file it can't find and why.

Roy Lambert [Team Elevate]
Wed, Jul 24 2013 4:43 AMPermanent Link

Abdulaziz Al-Jasser

It give the error at the bellow line:

EDBSession1.Execute(sSQL);

And it is impossible to do more debugging because the code is clear/clean and I don't know what is happing there!!!

Regards,
Abdulaziz Jasser
Wed, Jul 24 2013 4:54 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Abdulaziz


What does sSQL contain?

Roy Lambert [Team Elevate]
Wed, Jul 24 2013 7:00 AMPermanent Link

Abdulaziz Al-Jasser

Roy,

As shown in my previous posts it contains the RESTORE clause.

sSQL := 'RESTORE DATABASE %s FROM "%s" IN STORE "Backups" INCLUDE CATALOG';
sSQL := Format(sSQL,[rSystemData.DatabaseName,ExtractFileName(sBackupFileName)]);


This is a copy/paste from IDE debugger:

RESTORE DATABASE MyDatabase FROM "DB Backup As Of 23_7_2013_16_49.EDBBkp" IN STORE "Backups" INCLUDE CATALOG



NOTE: Basically I am trying to restore a backup that was taken from the same database.
Regards,
Abdulaziz Jasser
Wed, Jul 24 2013 7:48 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Abdulaziz


The only thing I can see that I think is wrong is that you have the filename in double quotes rather than single quotes.

Roy Lambert [Team Elevate]
Wed, Jul 24 2013 8:42 AMPermanent Link

Abdulaziz Al-Jasser

Roy,

I tried single quotes but I got syntax error.  I also tried to make the file name simple but still no luck...

Regards,
Abdulaziz Jasser
Page 1 of 2Next Page »
Jump to Page:  1 2
Image