Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

tsql - Is there a trick for using TSQLMonitor with a TSQLConnection that uses the new ODBC dbExpress driver?

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?

question from:https://stackoverflow.com/questions/8916788/is-there-a-trick-for-using-tsqlmonitor-with-a-tsqlconnection-that-uses-the-new-o

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...