[6.2.8 / SQLite] How to create an non existing SQLite database ?

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
swierzbicki
Posts: 451
Joined: Wed 19 Jan 2005 09:59

[6.2.8 / SQLite] How to create an non existing SQLite database ?

Post by swierzbicki » Wed 07 Oct 2015 12:28

I'm getting "Unable to open database file" on non existing database file despite setting SQLite.ForceCreateDatabase=True !

Code: Select all

procedure CreateDatabase;
var
  Connection_Locale: TUniConnection;
  Script_Local: TUniScript;

begin
  Connection_Locale := TUniConnection.Create(nil);
  Script_Local := TUniScript.Create(nil);

  try

    Script_Local.Connection := Connection_Locale;

    Connection_Locale.ProviderName := 'SQLite';
    Connection_Locale.Database := 'C:\Users\Public\Documents\SAS\Labels Printer\MyDB.DB3';
    Connection_Locale.LoginPrompt := false;
    Connection_Locale.SpecificOptions.Add('SQLite.ForceCreateDatabase=True');
    Connection_Locale.SpecificOptions.Add('SQLite.Direct=True');
    Connection_Locale.Connect;
    try
      Connection_Locale.StartTransaction;
      Script_Local.SQL.Text := 'CREATE TABLE Ref_Compteurs (Reference string NOT NULL,Compteur integer,PRIMARY KEY (Reference));';
      Script_Local.Execute;
      Connection_Locale.Commit;
    except
      on e: Exception do
      begin
        if Connection_Locale.Connected then
          Connection_Locale.Rollback;
        raise;
      end;
    end;
  finally
    try
      if Connection_Locale.Connected then
        Connection_Locale.Close;
      Script_Local.Free;
      Connection_Locale.Free;
    except
    end;
  end;
end;
Looks like I'm doing something wrong but I can't see it !

swierzbicki
Posts: 451
Joined: Wed 19 Jan 2005 09:59

Re: [6.2.8 / SQLite] How to create an non existing SQLite database ?

Post by swierzbicki » Wed 07 Oct 2015 12:44

It appears that folder "C:\Users\Public\Documents\SAS\Labels Printer\" doesn't exists.
Creating it solved the problem.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: [6.2.8 / SQLite] How to create an non existing SQLite database ?

Post by AlexP » Thu 08 Oct 2015 04:48

Hello,

Glad to see that you solved the problem. If you have any other questions, feel free to contact us.

Post Reply