将TSQLMonitor与使用新ODBC dbExpress驱动程序的TSQLConnection一起使用是否有技巧?

时间:2012-01-18 20:15:22

标签: tsql delphi delphi-xe2 dbexpress

我一直在测试Delphi XE2附带的新ODBC dbExpress驱动程序,并注意到TSQLMonitor似乎不起作用。考虑到我可能错误地配置了组件,我将TSQLMonitor连接到使用MS SQL dbExpress驱动程序的TSQLConnection,这就像魅力一样。

我在网上看不到有关此问题的任何帖子。有没有人注意到这个问题?它是否是一个错误,一个不受支持的功能(在使用ODBC驱动程序的TSQLConnection上没有监视),或者在这种情况下配置TSQLMonitor是否有技巧?

1 个答案:

答案 0 :(得分: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;