嘗試了這一點:
procedure TForm2.Button1Click(Sender: TObject);
begin
try
Connect;
SQLMonitor1.SQLConnection := SQLConnection1;
SQLMonitor1.Active := True;
ExecuteQueries;
SQLMonitor1.SaveToFile('D:\\Log.txt');
except
on E: Exception do
ShowMessage('Exception ocurred!: ' + E.Message);
end;
end;
procedure TForm2.Connect;
begin
SQLConnection1 := TSQLConnection.Create(nil);
SQLConnection1.ConnectionName := 'odbcinterbaseconnection';
SQLConnection1.LoginPrompt := False;
SQLConnection1.LoadParamsOnConnect := True;
SQLConnection1.Connected := True;
end;
procedure TForm2.ExecuteQueries;
var
Query: String;
begin
try
if SQLConnection1.Connected then
begin
Query := 'CREATE TABLE ExampleTable(id INTEGER, name VARCHAR(50))';
SQLConnection1.Execute(Query, nil);
Query := 'INSERT INTO ExampleTable VALUES(1,''test1'')';
SQLConnection1.Execute(Query, nil);
Query := 'INSERT INTO ExampleTable VALUES(2,''test2'')';
SQLConnection1.Execute(Query, nil);
Query := 'INSERT INTO ExampleTable VALUES(3,''test3'')';
SQLConnection1.Execute(Query, nil);
Query := 'SELECT * FROM ExampleTable';
SQLConnection1.Execute(Query, nil);
end;
except
on E: Exception do
ShowMessage('Exception ocurred!: ' + E.Message);
end;
end;
你有沒有嘗試使用導出驅動程序跟蹤?這增加了SQLMonitor的結果,並可能最終變得有用。如果ODBC驅動程序是一個完全本地驅動程序(正如我所想象的那樣),它可能與「舊」基於Dll的驅動程序不一樣。...... – 2012-01-18 21:02:33
Marco:這是一個很好的建議。將TSQLConnection連接到ODBC驅動程序,然後展開TSQLConnection的Driver屬性後,我將驅動程序的DelegateConnection屬性設置爲DBXTrace。然後我展開DelegateConnection屬性並將TraceFile設置爲True並將TraceFile設置爲文件名(全部按照您的建議)。感謝您的解決方法。我仍然想知道是否有人知道如何解決TSQLMonitor問題。 – 2012-01-18 21:34:21
@MarcoCantù:有點主題,但請你可以考慮這[後](http://stackoverflow.com/questions/10147850/add-my-own-items-to-delphi-ide-insight-f6-with -in-德爾福開工具-API)? – menjaraz 2012-04-14 07:10:41