How to free or share the access to my .fdb (FireBird database file) ? lazarus / 16-Databases ---------------------------------------------------------------------- yanes19 · 2014-01-30 20:31 Hi all , My program uses a FireBird database with an embedded server  in which it stores and query data , Every thing is ok , But I have a small tool that  expected to backup the DB and the user settings at any time my users asks it to do . The backup program is launched as a TProcess  , But it can't access the .fdb (the DB file ) it reports the error as (file used by another process) , the code Code: [Select]  Archiver := TProcess.Create(nil);   OutputStringList := TStringList.Create;   Archiver.Options := Archiver.Options + [poWaitOnExit, poUsePipes];   Archiver.Executable := 'MyArchiver.exe ';   Archiver.Parameters.Add(BackupDir + '\backup'+IntToStr(DayOf(now())) +'_' +                         IntToStr(MonthOf(now()))+'_'+IntToStr(YearOf(now()))+'.Bak'); // I closed all the queries and disconnected from the DB to free the fdb file , but no luck   SQLTransaction1.Active:= False;   SQLQuery2.Close;   SQLQuery1.Close;   IBConnection1.Connected:= False;   IBConnection1.DropDB;   Archiver.Parameters.Add(IBConnection1.DatabaseName);   Archiver.Execute;   OutputStringList.LoadFromStream(Archiver.Output);   ShowMessage(OutputStringList.Text);   Archiver.Free; // restore my connection   IBConnection1.DatabaseName:='Data.FDB';   IBConnection1.Connected:= True;    How to share access to my DB file with my archiver process or free the file temporarily from my embedded server and restore my connection later after the backup thanks in advance ---------------------------------------------------------------------- kpeters58 · 2014-01-30 21:36 Not sure if that is supposed to be possible...?? I imagine you'd have to use the nbackup tool that comes with FB for this purpose. ---------------------------------------------------------------------- yanes19 · 2014-01-30 21:45 Thank you for replying but, I forgot to note that my program uses an embedded server  so my server is included in my own application "original post updated  " ---------------------------------------------------------------------- mangakissa · 2014-01-31 08:10 How to backup the embedded database? You have two alternatives: 1. Do the backup using Services API from your application. It works just like a regular backup done by the full server. 2. If your connectivity library does not support Services API for backup, you can use GBAK with embedded library. In this case you need to disconnect from the database as only one application can be connected at a time (and GBAK counts as a separate application). http://www.firebirdfaq.org/faq303/ ---------------------------------------------------------------------- taazz · 2014-01-31 08:25 or download and use the latest embedded server (2.5 or later if memory serves me correctly) that can share a database with other applications on the same machine. ---------------------------------------------------------------------- BigChimp · 2014-01-31 10:36 Depending on exactly what you call with Archiver (e.g. gbak.exe, nbackup.exe, even if it is only calling zip to zip the .fdb) IMO it should be possble. Maybe the firebird dll needs to do some cleanup - which it perhaps does in a separate thread? Have you experimented with adding some Code: [Select]sleep(100); //or whatever calls after IBConnection1.Connected:= False; Also, I'd check in code if IBConnection1.Connected is really false. Perhaps there's some component you forgot that's holding the connection open? What I wonder about is the DropDB call which instructs ibconnection to remove the .fdb from disk - surely something you don't want? http://www.freepascal.org/docs- html/fcl/ibconnection/tibconnection.dropdb.html Edited: added backup utility names for clarity ---------------------------------------------------------------------- yanes19 · 2014-01-31 15:00 @ TAZZ : my DLLs product versions for  fembed.dll and ib_util.dll are  :2.5.2.26xx so my server seems to be  ~ up to date @ mangakissa : i'll search for the apis tonight and see if that works , @BigChimp : You are our hero  , I added the "sleep(100);" but no luck ! yeah , I know the drop DB method is dangerous !! but it was just a simple essay when all other procedures failed , but It didnt remove the DB because it was disconnected and this procedure requires the DB to be connected properly , In a Final  word , Do you advise that I switch to install the external FireBird server ? I think ,It doesnt need lot of changes and give me more of flexibility , and I'm always in doubt about my embedded server stability ! ---------------------------------------------------------------------- yanes19 · 2014-02-15 21:57 Ok , I think it was solved , My final solution was to Prompt the user to allow an application restart in order to free the FDB file and allow the backup tool to access the file The FireBirds APIs Allow a backup But a custom tool gives more of flexibility