Building connection string in the code
Posted: 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
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