tobenschain 0 Posted May 14 I am unable to delete a TFDTable after creating it. I tried Close and Disconnect. Share this post Link to post
weirdo12 21 Posted May 14 14 minutes ago, tobenschain said: I am unable to delete a TFDTable after creating it. I tried Close and Disconnect. What database are you using? Show us the code you are using that is not working as expected along with an explanation of what you think should be happening. Share this post Link to post
tobenschain 0 Posted May 14 Using SQLite Module_DB: TFDTable; Module_DB.Close; Module_DB.Disconnect; SysUtils.DeleteFile('Test.DB'); Share this post Link to post
tobenschain 0 Posted May 14 if I try to delete the file manually it says it's still in use by the program Share this post Link to post
Remy Lebeau 1436 Posted May 14 (edited) 11 minutes ago, tobenschain said: if I try to delete the file manually it says it's still in use by the program Are you sure it is YOUR program that has the file open? Did you verify that, such has with a tool like SysInternals Process Explorer? Maybe the file is open by the OS, or an antivirus/antimalware, etc. Edited May 14 by Remy Lebeau Share this post Link to post
weirdo12 21 Posted May 14 In the direction Remy suggested, maybe TFDConnection,Connected = true in the IDE. Share this post Link to post
Cristian Peța 107 Posted May 15 Closing a table will not close the connection to the database and if you are using PRAGMA locking_mode=EXCLUSIVE then you need to close the connection to unlock the file. Using locking_mode=NORMAL and deleting the file with an open connection is not a good thing. In this case you don't need to close the table either. https://www.sqlite.org/pragma.html#pragma_locking_mode 1 Share this post Link to post
Brian Evans 109 Posted May 15 This might not apply but: most databases have temporary tables of various lifetimes. SQLite has temporary tables that are database session specific and go away on their own when the session is closed. Share this post Link to post
Cristian Peța 107 Posted May 16 (edited) Have you checked what PRAGMA locking_mode is returning? You can use TFDQuery for this. With UniDAC implicit is EXCLUSIVE and maybe also for FireDAC. Can you delete the file before opening any connection? Better try this after a system restart (or unlock the file) because if you kill the processes in debug, for example, before the connection is closed the file will remain locked. PS: I prefer to use locking_mode=NORMAL. There is some performance penalty but I don't need any more to respond with: restart the OS. Edited May 16 by Cristian Peța Share this post Link to post
tobenschain 0 Posted May 16 <<Have you checked what PRAGMA locking_mode is returning?>> I use: ExecSQL('PRAGMA locking_mode = NORMAL'); <<Can you delete the file before opening any connection?>> The file is being created. Share this post Link to post
Cristian Peța 107 Posted May 16 54 minutes ago, tobenschain said: Created, Copied and Deleted That means you solved the issue using locking_mode = NORMAL? Then probably you have not closed the connection properly before trying to delete. Share this post Link to post
tobenschain 0 Posted May 16 This is what I do Module_DB.Close; Module_DB.Disconnect; Module_Con.Close; Share this post Link to post
Cristian Peța 107 Posted May 17 This is working for me. Probably you are doing something else in your code. program Project1; {$APPTYPE CONSOLE} uses System.SysUtils, System.Variants, System.Classes, FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.SQLite, FireDAC.Phys.SQLiteDef, FireDAC.Stan.ExprFuncs, FireDAC.VCLUI.Wait, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, FireDAC.Phys.SQLiteWrapper.Stat, Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client; var FDConnection1: TFDConnection; FDTable1: TFDTable; begin FDConnection1 := TFDConnection.Create(nil); FDTable1 := TFDTable.Create(nil); FDConnection1.DriverName := 'SQLite'; FDConnection1.Params.Database := ExtractFilePath(ParamStr(0)) + 'test.db'; FDTable1.Connection := FDConnection1; FDTable1.TableName := 'table1'; //Default FDConnection1.Params.Values['LockingMode'] is 'Exclusive' FDConnection1.Open; FDConnection1.ExecSQL('CREATE TABLE table1 (a INTEGER)'); FDTable1.Open; FDTable1.InsertRecord([10]); FDTable1.Close; DeleteFile(FDConnection1.Params.Database);//here is not working because LockingMode = Exclusive FDConnection1.Close; DeleteFile(FDConnection1.Params.Database);//here is working for me end. Share this post Link to post
tobenschain 0 Posted May 18 I needed: try FDQuery1.ExecSQL('insert into MyTab(code, name) values (:code, :name)', [100, 'Tokyo']); except on E: EFDDBEngineException do begin // E.Message - Actual error message. For the DBMS messages only Message property is used. // E.ErrorCode - DBMS-specific error code. // E.Kind - DBMS-independent error code and other properties. if E.Kind = ekUKViolated then ShowMessage('Please enter unique value !'); raise; end; end; Share this post Link to post