0% found this document useful (0 votes)
148 views4 pages

Using TSQLMonitor With An ODBC Connection - RAD Studio

This tutorial shows how to use TSQLMonitor with an ODBC connection to monitor SQL statements sent to an Interbase database. It involves creating an ODBC data source, connecting via TSQLConnection, assigning the connection to TSQLMonitor, executing sample queries, and saving the trace log to a file. The example creates a table, inserts some records, runs a select statement, and saves the trace log to demonstrate monitoring SQL executed against the ODBC data source.

Uploaded by

Juli Adi Prastyo
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
148 views4 pages

Using TSQLMonitor With An ODBC Connection - RAD Studio

This tutorial shows how to use TSQLMonitor with an ODBC connection to monitor SQL statements sent to an Interbase database. It involves creating an ODBC data source, connecting via TSQLConnection, assigning the connection to TSQLMonitor, executing sample queries, and saving the trace log to a file. The example creates a table, inserts some records, runs a select statement, and saves the trace log to demonstrate monitoring SQL executed against the ODBC data source.

Uploaded by

Juli Adi Prastyo
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Tutorial: Using TSQLMonitor with an ODBC Connection - RAD Studio

http://docwiki.embarcadero.com/RADStudio/XE5/en/Tutorial:_Using_T...

Show: Delphi C++ Display Preferences

Tutorial: Using TSQLMonitor with an ODBC Connection


From RAD Studio Go Up to Tutorials#SQLite and SQLMonitor In RAD Studio XE3, TSQLMonitor offers support for ODBC connections. The following tutorial shows how TSQLMonitor can be used with an ODBC connection. The ODBC establishes a connection to an Interbase database. The example is a VCL Form Applications that contains 3 controls: TSQLConnection, TSQLMonitor, and TButton. When the button is clicked, a table is created and populated with data, and then a simple select query is executed. Finally, the TraceList of the TSQLMonitor is saved to a file on disk.

Contents
1 Steps 1.1 Create the connection to the ODBC datasource 1.2 The application 2 See Also

Steps
Create the connection to the ODBC datasource
1. Create an ODBC datasource. For more information, see: Microsoft documentation (http://msdn.microsoft.com/en-us/library/ca6axakh(v=vs.80).aspx) . 2. From the Data Explorer, right-click Odbc, and select Add New Connection.

1 of 4

12/23/2013 5:13 PM

Tutorial: Using TSQLMonitor with an ODBC Connection - RAD Studio

http://docwiki.embarcadero.com/RADStudio/XE5/en/Tutorial:_Using_T...

3. Select a name for the new connection and click OK. In this example, we will use ODBCINTERBASECONNECTION. 4. Right-click the newly created connection, and select Modify. Set the Database field to the name of the Datasource created with ODBC Data Source Administrator (http://msdn.microsoft.com/en-us/library /windows/desktop/ms714024(v=vs.85).aspx) , and the credentials needed to connect to the database.

5. Click Test Connection. If the connections has been properly set, a dialog box stating Test connection succeeded should be displayed.

The application
1. Select File > New > VCL Forms Application - Delphi. 2. Add the following controls the form: a TSQLConnection, a TSQLMonitor, and a TButton. 3. Add the following code to the OnClick event handler of the TButton control:

2 of 4

12/23/2013 5:13 PM

Tutorial: Using TSQLMonitor with an ODBC Connection - RAD Studio

http://docwiki.embarcadero.com/RADStudio/XE5/en/Tutorial:_Using_T...

procedure TForm2.Button1Click(Sender: TObject); begin try Connect; SQLMonitor1.SQLConnection := SQLConnection1; // Activate the Monitor SQLMonitor1.Active := True; ExecuteQueries; // Write the trace list of the TSQLMonitor to a file on disk SQLMonitor1.SaveToFile('D:\\Log.txt'); except on E: Exception do ShowMessage('Exception raised with message: ' + E.Message); end; end;

Here is the code for the functions called in the OnClick event handler of the TButton control:
// establishes the connection to the ODBC datasource procedure TForm2.Connect; begin SQLConnection1 := TSQLConnection.Create(nil); // the name of the connection created in the data explorer SQLConnection1.ConnectionName := 'odbcinterbaseconnection'; SQLConnection1.LoginPrompt := False; SQLConnection1.LoadParamsOnConnect := True; SQLConnection1.Connected := True; end; // Executes several queries on the database. 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 raised with message: ' + E.Message); end; end;

See Also
Tutorial: TSQLMonitor support for SQLite databases Data.SqlExpr.TSQLMonitor

3 of 4

12/23/2013 5:13 PM

Tutorial: Using TSQLMonitor with an ODBC Connection - RAD Studio

http://docwiki.embarcadero.com/RADStudio/XE5/en/Tutorial:_Using_T...

Data.SqlExpr.TSQLConnection FMX.Controls.TButton Data.SqlExpr.TSQLMonitor.TraceList Object Inspector Data.SqlExpr.TSQLConnection.DriverName Data.SqlExpr.TSQLMonitor.SQLConnection Vcl.Controls.TControl.Caption Vcl.StdCtrls.TButton.OnClick Data.SqlExpr.TSQLConnection.Execute Data.SqlExpr.TSQLConnection.Connected Data.SqlExpr.TSQLMonitor.Active Data.SqlExpr.TSQLMonitor.SaveToFile Retrieved from "http://docwiki.embarcadero.com/RADStudio/XE5/e /index.php?title=Tutorial:_Using_TSQLMonitor_with_an_ODBC_Connection&oldid=212426" This page was last modified on 25 October 2013, at 17:59. Help Feedback

4 of 4

12/23/2013 5:13 PM

You might also like