Autor Beitrag
jjturbo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 516

Win2000 prof., WinXP prof.
D4 Stand., D5 Prof, D7 Prof, D2007 Prof.
BeitragVerfasst: Mi 17.07.13 16:36 
Moin Forum,

wenn ich eine TZConnction mit dem Protokoll firebird-2.1 verwende (DB ist eine Firebird auf einem PC im LAN) dann bekomme ich bei einem Select mit einer TZQuery keine aktuellen Daten zurück. Erst wenn ich die TZConnection schliesse und neu öffne (mit Disconnect und connect) kann ich per Select auf dem Query die aktuellen Daten sehen.

Als zweite Option (Auch mit TZConnection+TZQuery) verwende ich das Protokoll ado und verbinde mich mit einer ODBC-Quelle(Die natürlich auf die gleiche DB zeigt). Hierbei wird nach jedem Select der aktuelle Datenbestand angezeigt.

Ich hoffe Ihr könnt mir helfen?

Danke im voraus, Oliver

Hier noch mein Bespielcode:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
unit AA_TestUnit_Firebird;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, Grids, DBGrids, ZAbstractRODataset, ZAbstractDataset, ZDataset,
  ZConnection, StdCtrls;

type
  TForm2 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form2                    :TForm2;

  myZConnection1           :TZConnection;
  myZConnection2           :TZConnection;

  myZQuery1                :TZQuery;
  myZQuery2                :TZQuery;

  myDataSource1             :TDataSource;
  myDataSource2             :TDataSource;

  myDBGrid1                :TDBGrid;
  myDBGrid2                :TDBGrid;


implementation

{$R *.dfm}














procedure ExecSQL_ZQuery(MyQuery:TZQuery;SQLText:String);
begin


  if MyQuery <> nil then begin
    if not MyQuery.Connection.Connected
     then Exit;

    MyQuery.Active := false;
    MyQuery.SQL.Clear;
    MyQuery.SQL.SetText(PChar(SQLText));

    TRY
      if Pos('SELECT',UpperCase(SQLText)) = 0
       then MyQuery.ExecSQL
       else MyQuery.Active := True;
    EXCEPT
      on E : Exception
       do ShowMessage('SQL Error = ' + E.Message + #13 + 'SQL String = ' + SQLText);
    END;
  end;


end;








procedure TForm2.Button1Click(Sender: TObject);
var SQLText :String;
begin

  SQLText := 'SELECT * FROM hc_lagerbestand';
  ExecSQL_ZQuery(myZQuery1,PChar(SQLText));

  SQLText := 'SELECT * FROM hc_lagerbestand';
  ExecSQL_ZQuery(myZQuery2,PChar(SQLText));

end;










procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin

  myZQuery1.Close;
  myZConnection1.Disconnect;

  FreeAndNil(myDBGrid1);
  FreeAndNil(myDataSource1);
  FreeAndNil(myZQuery1);
  FreeAndNil(myZConnection1);


  myZQuery2.Close;
  myZConnection2.Disconnect;

  FreeAndNil(myDBGrid2);
  FreeAndNil(myDataSource2);
  FreeAndNil(myZQuery2);
  FreeAndNil(myZConnection2);

end;










procedure TForm2.FormCreate(Sender: TObject);
begin

  myZConnection1          := TZConnection.Create(Form2);
  myZQuery1               := TZQuery.Create(Form2);
  myDataSource1           := TDataSource.Create(Form2);
  myDBGrid1               := TDBGrid.Create(Form2);
  myDBGrid1.Parent        := Form2;


  myDBGrid1.Left          := 10;
  myDBGrid1.Top           := 10;
  myDBGrid1.Width         := 400;
  myDBGrid1.Height        := 260;


  myDBGrid1.DataSource    := myDataSource1;
  myDataSource1.DataSet   := myZQuery1;
  myZQuery1.Connection    := myZConnection1;

  myZConnection1.Database := 'C:\temp\AA_Testdatenbanken_Firebird\hc2301_lager.fdb';
  myZConnection1.HostName := 'hc_firebird';
  myZConnection1.Protocol := 'firebird-2.1';
  myZConnection1.User     := 'sysdba';
  myZConnection1.Password := 'masterkey';
  myZConnection1.Connect;

  myZQuery1.SQL.SetText(PChar('SELECT * FROM hc_lagerbestand'));
  myZQuery1.Active        := True;






  myZConnection2          := TZConnection.Create(Form2);
  myZQuery2               := TZQuery.Create(Form2);
  myDataSource2           := TDataSource.Create(Form2);
  myDBGrid2               := TDBGrid.Create(Form2);
  myDBGrid2.Parent        := Form2;


  myDBGrid2.Left          := 420;
  myDBGrid2.Top           := 10;
  myDBGrid2.Width         := 400;
  myDBGrid2.Height        := 260;


  myDBGrid2.DataSource    := myDataSource2;
  myDataSource2.DataSet   := myZQuery2;
  myZQuery2.Connection    := myZConnection2;

  myZConnection2.Database := 'hc2301_lager';
  myZConnection2.HostName := '';
  myZConnection2.Protocol := 'ado';
  myZConnection2.User     := 'sysdba';
  myZConnection2.Password := 'masterkey';
  myZConnection2.Connect;

  myZQuery2.SQL.SetText(PChar('SELECT * FROM hc_lagerbestand'));
  myZQuery2.Active        := True;


end;







end.

_________________
Windows XP: Für die einen nur ein Betriebssystem - für die anderen der längste Virus der Welt...
jjturbo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 516

Win2000 prof., WinXP prof.
D4 Stand., D5 Prof, D7 Prof, D2007 Prof.
BeitragVerfasst: Do 18.07.13 14:51 
Habe die Lösung gefunden:

TransactionIsolationLevel auf tiReadCommitted setzen, dann funzt es.

Danke an alle.

_________________
Windows XP: Für die einen nur ein Betriebssystem - für die anderen der längste Virus der Welt...