Building connection string in the code

Discussion of open issues, suggestions and bugs regarding LiteDAC (SQLite Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
thorgal
Posts: 10
Joined: Fri 18 Sep 2009 14:33

Building connection string in the code

Post by thorgal » Thu 21 Aug 2014 18:45

Hello,
I am testing liteDac library.
I can connect to the database when I drop the component on the VCL form.
I was trying to do the same thing in the code; however, I get error when I try to establish connection. Any help would be appreciated.
sqliteQuery : TLiteQuery;
sqliteConnection : TLiteConnection;
sqlQry : TSqlStatements;
databasePath : string;
begin
databasePath := 'C:\Users\chris\Documents\Dev\Delphi\sqlite_test\dv.db3';
sqlQry := TSqlStatements.create(FUserInput);

sqliteConnection := TLiteConnection(nil);
sqliteQuery := TLiteQuery.Create(nil);

try
sqliteConnection.LoginPrompt := false;
sqliteConnection.Database := databasePath;
sqliteConnection.Options.Direct := true;

if not(sqliteConnection.Connected) then
sqliteConnection.Open;

sqliteQuery.ReadOnly := true;
sqliteQuery.SQL.Clear;
sqliteQuery.SQL.Add(sqlQry.stateSql);
sqliteQuery.Prepared := true;
sqliteQuery.Execute;

I tried to use a connection string:
sqliteConnection.ConnectString:= 'Login Prompt=False;Database=C:\Users\tpdzaja\Documents\Dev\Delphi\sqlite_fireDac\dv.db3;Direct=True';

Did not work.
I would appreciate any help.
Thanks,
Chris

ZEuS
Devart Team
Posts: 240
Joined: Thu 05 Apr 2012 07:32

Re: Building connection string in the code

Post by ZEuS » Fri 22 Aug 2014 08:46

Unfortunately, we can not reproduce the problem. We have modified the code you provided to use with the connection string, and it works without any problems.

Code: Select all

...
try
  sqliteConnection.ConnectString:= 'Login Prompt=False;Database=C:\Users\tpdzaja\Documents\Dev\Delphi\sqlite_fireDac\dv.db3;Direct=True';

  if not(sqliteConnection.Connected), then
    sqliteConnection.Open;
...
Can you explain in more details what do you mean by "did not work". What is the exact error message you are getting?

thorgal
Posts: 10
Joined: Fri 18 Sep 2009 14:33

Re: Building connection string in the code

Post by thorgal » Fri 22 Aug 2014 12:34

Hello,
I rewrote the routine from the beginning and it worked.
I am not sure why I could not get to work in the first place.
I am sorry for extra trouble.
On a better note, I like the LiteDac library. I will buy; plus your help files are much better than FireDac.

Chris

ZEuS
Devart Team
Posts: 240
Joined: Thu 05 Apr 2012 07:32

Re: Building connection string in the code

Post by ZEuS » Fri 22 Aug 2014 12:52

Thank you for your interest in our products.
Feel free to contact us if you have any further questions about LiteDAC.

Post Reply