William23668 8 Posted December 31, 2021 Hi I am using this code to create the database bute I get error on connect : var MyDBFile: string; begin MyDBFile := 'C:\db5.sqlite3'; if FileExists(MyDBFile) then DeleteFile(MyDBFile); FDConnection1.Params.Values['Database'] := MyDBFile; FDConnection1.Params.Values['DriverID'] := 'SQLite'; //Connection.Params.Values['Encrypt'] := 'aes-128'; //Connection.Params.Values['Password'] := '1234'; FDConnection1.Connected := True; --------------------------- [FireDAC][Phys][SQLite] ERROR: unable to open database file. --------------------------- Share this post Link to post
limelect 48 Posted December 31, 2021 (edited) 1.use FDConnection1 2.FDConnection1BeforeConnect >>>>FDConnection1.Params.Values['Database'] := 'Applications.db'; 3. FDConnection1AfterConnect>>>> FDConnection1.ExecSQL('CREATE TABLE IF NOT EXISTS Files (SectionsId INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,MainDirectory TEXT NULL, Files TEXT NULL)'); FilesFDTable.TableName := 'Files'; FilesFDTable.Active := True; Now you can use table or sql Edited December 31, 2021 by limelect Share this post Link to post
William23668 8 Posted December 31, 2021 18 minutes ago, limelect said: 1.use FDConnection1 2.FDConnection1BeforeConnect >>>>FDConnection1.Params.Values['Database'] := 'Applications.db'; 3. FDConnection1AfterConnect>>>> FDConnection1.ExecSQL('CREATE TABLE IF NOT EXISTS Files (SectionsId INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,MainDirectory TEXT NULL, Files TEXT NULL)'); FilesFDTable.TableName := 'Files'; FilesFDTable.Active := True; Now you can use table or sql I dont understand !! the code display error on connect so it does not connect or create a file. Share this post Link to post
limelect 48 Posted December 31, 2021 @William23668 show your code and your error did you try my code? The code I put is from my program Share this post Link to post
KenR 29 Posted January 1, 2022 (edited) Do you have the CreateDatabase param set. e.g. FDConnection1.Params.Values['CreateDatabase']:=BoolToStr(not FileExists(FDConnection1.Params.Database),True); Edited January 1, 2022 by KenR 2 Share this post Link to post
William23668 8 Posted January 1, 2022 36 minutes ago, KenR said: Do you have the CreateDatabase param set. e.g. FDConnection1.Params.Values['CreateDatabase']:=BoolToStr(not FileExists(FDConnection1.Params.Database),True); wow this solved the problem, I never read about this parameter before. many thanks Share this post Link to post
KenR 29 Posted January 1, 2022 14 minutes ago, William23668 said: wow this solved the problem, I never read about this parameter before. many thanks Great. Pleased I could help. Share this post Link to post
John Terwiske 4 Posted January 2, 2022 Your code does indeed work without modification. *****Provided you run it with permission to write to the root of "C" drive (i.e. run as Adminstrator).*** It's not a bug, it's a feature! 🙂 Share this post Link to post