Page 1 of 1

SQLite connect setup

Posted: 11.04.2011, 12:37
by Wathfea
Hi All!

I'm quite fustrated because I don't understand why this connect what i set up do what is doing. :D

So.

I'm developing under Delphi 7 Enterprise and using Zeos 6.6.6

I have a DM unite where i put a Zeos connection.
Under the IDE I set Conencted: False; Host: nothing; Databse: cash.sqlite; Port: 0; Protocol: sqlite-3;
I put also one query not read-only and set the connection to the Zeos conenct, and set active: false;

And here is my other unit.

Code: Select all

unit Config;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, XPMan, StdCtrls, INIFiles, DMUnite, Grids, DBGrids;

type
  TTConfig = class(TForm)
    Panel1: TPanel;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    DBHost: TEdit;
    GroupBox3: TGroupBox;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Fullname: TEdit;
    User: TEdit;
    Pass: TEdit;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Mentes: TButton;
    procedure MentesClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  TConfig: TTConfig;

implementation

{$R *.dfm}

procedure TTConfig.MentesClick(Sender: TObject);
var myINI:TINIFile;
var ADDUser,ADDPass,ADDFullname,ADDToday:string;
var today : TDateTime;
begin

    //Config.ini letrehozasa
    myINI := TINIFile.Create(ExtractFilePath(Application.EXEName) + 'config.ini');
    myINI.WriteString('Settings', 'Host', DBHost.Text);
    myINI.Free;

    today:=Now;
    //Az elso user beszúrása a DB-be.
    ADDUser := QuotedStr(User.Text);
    ADDPass:= QuotedStr(Pass.Text);
    ADDFullname:=QuotedStr(Fullname.Text);
    ADDToday:=QuotedStr(DateToStr(today));


    //Elso kapcsolat belovese
   Try
    Showmessage('Hamarosan kapcsolódom');
    DMUnite.DM.Connect.HostName:=DBHost.Text;
    DMUnite.DM.Connect.Connect;
    if DMUnite.DM.Connect.Connected then
    Showmessage('Sikeresen kapcsolódtam')
    else
    Showmessage('nem sikerult')
    except
    Showmessage('Hiba a kapcsolodaskor');
   end;

    //Admin beszúrás
    DMUnite.DM.Query.Active:=True;
    DMUnite.DM.Query.SQL.Clear;
    DMUnite.DM.Query.SQL.Add('INSERT INTO `user` (`user_name`,`user_pass`,`is_admin`,`full_name`,`last_login`,`active`) values ');
    DMUnite.DM.Query.SQL.Add(' ('+ADDUser+','+ADDPass+',''1'','+ADDFullname+','+ADDToday+',''1'') ');
    DMUnite.DM.Query.ExecSQL;
    ShowMessage('Köszönöm szépen, kérem indítsa újra a programot!');
end;
end.
I copied my cash.sqlite db file to host: 81.16.200.84
But it won't connect to the host. It's ALWAYS use the localhost and use the DB file which is on my computer.
Plz help me to use other host than localhost.

Best regards,

Wathfea

Posted: 11.04.2011, 13:40
by jeremicm
I don't think you can connect to .db file directly on remote server...

Posted: 12.04.2011, 08:25
by trupka
It is possible to use remote server for sqllite but only through some kind of file sharing. Example for Windows (smb/cifs) networks:

Code: Select all

  ZConnection1.HostName := '';
  ZConnection1.Database := '\\server\share\database_file';
  ZConnection1.Connect;
but this is one of those not-so-good ideas. Better use some real client/server database. You can find more about this on http://www.sqlite.org/whentouse.html