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

发布于 2024-12-27 15:17:07 字数 283 浏览 0 评论 0原文

我一直在测试 Delphi XE2 附带的新 ODBC dbExpress 驱动程序,并注意到 TSQLMonitor 似乎不起作用。我认为我可能错误地配置了该组件,因此将 TSQLMonitor 连接到使用 MS SQL dbExpress 驱动程序的 TSQLConnection,效果非常好。

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

I have been testing the new ODBC dbExpress driver that ships with Delphi XE2, and have noticed that the TSQLMonitor does not seem to work. Thinking that I may have configured the component incorrectly, I hooked up a TSQLMonitor to a TSQLConnection that uses the MS SQL dbExpress driver, and that worked like a charm.

I don't see any posts about this problem on the Web. Has anyone else noticed this issue? Does it appear to be a bug, an unsupported feature (no monitoring on a TSQLConnection that uses the ODBC driver), or is there a trick to configuring the TSQLMonitor under this condition?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悟红尘 2025-01-03 15:17:07

试试这个:

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;

Try this out:

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文