Page 1 of 1

Building connection string in the code

Posted: Thu 21 Aug 2014 18:45
by thorgal
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

Re: Building connection string in the code

Posted: Fri 22 Aug 2014 08:46
by ZEuS
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?

Re: Building connection string in the code

Posted: Fri 22 Aug 2014 12:34
by thorgal
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

Re: Building connection string in the code

Posted: Fri 22 Aug 2014 12:52
by ZEuS
Thank you for your interest in our products.
Feel free to contact us if you have any further questions about LiteDAC.