2012-01-18 17 views
38

我一直在測試Delphi XE2附帶的新的ODBC dbExpress驅動程序,並且注意到TSQLMonitor似乎不起作用。考慮到我可能已經錯誤地配置了組件,我將TSQLMonitor連接到了使用MS SQL dbExpress驅動程序的TSQLConnection,並且像魅力一樣工作。使用TSQLMonitor和使用新的ODBC dbExpress驅動程序的TSQLConnection有沒有訣竅?

我在網上看不到任何有關此問題的文章。有沒有人注意到這個問題?它看起來是一個錯誤,一個不受支持的功能(在使用ODBC驅動程序的TSQLConnection上沒有進行監視),還是在這種情況下配置TSQLMonitor有竅門?

+0

你有沒有嘗試使用導出驅動程序跟蹤?這增加了SQLMonitor的結果,並可能最終變得有用。如果ODBC驅動程序是一個完全本地驅動程序(正如我所想象的那樣),它可能與「舊」基於Dll的驅動程序不一樣。...... – 2012-01-18 21:02:33

+1

Marco:這是一個很好的建議。將TSQLConnection連接到ODBC驅動程序,然後展開TSQLConnection的Driver屬性後,我將驅動程序的DelegateConnection屬性設置爲DBXTrace。然後我展開DelegateConnection屬性並將TraceFile設置爲True並將TraceFile設置爲文件名(全部按照您的建議)。感謝您的解決方法。我仍然想知道是否有人知道如何解決TSQLMonitor問題。 – 2012-01-18 21:34:21

+0

@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

回答

1

嘗試了這一點:

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; 
相關問題