IBM Database Add-Ins for Visual Studio

Selecting Data Connections for Capturing SQL Statements  (DB2)

Before you can capture SQL statements, you must select a connection for each of the DB2® databases that the .NET application uses. A separate capture file is created for each connection, and you can change the default information for each capture file.

You can capture SQL statements for all of the databases that an application uses in a single pass, or you can capture the SQL in multiple passes.

Prerequisites:

To select the data connections for capturing SQL statements:

  1. In the Solution Explorer, right-click the project that contains the .NET application, and then select Optimize IBM SQL Queries.

    The Set Up .NET Application to Optimize SQL Queries window opens.

  2. For each data connection that is associated with a DB2 database that the .NET application uses, perform the following steps:
    1. If you ran the SQL statements for the connection statically in a previous pass, set its Run SQL value to Off.
    2. Set its Capture SQL value to On.

      If a data connection is not in the list, click New Connection, and then define the data connection in the Add Connection window.

    3. Optional: Specify the name of the capture file, collection, and package.

      If you capture SQL statements for only some data connections at a given time, consider specifying the names of capture files so that previous capture information is not overwritten. If you specify the name of a capture file, its extension must remain .capt.

  3. Click OK.


If the .NET application project does not contain an application configuration (app.config) file, the file is created and added to the project folder in the Solution Explorer. If the app.config file exists because the SQL statements were previously captured and bound, the content of the file is overwritten with the current information.

For each data connection whose Capture SQL value you set to On in the Set Up .NET Application to Optimize SQL Queries window, a child element is added to the <connectionStrings> element. A corresponding child element that contains the specific information for the data connection is added to the <appSettings> element.

For capture purposes, the value of a captureMode keyword is set to ON. After you click OK in the Set Up .NET Application to Optimize SQL Queries window, the keyword value is set to ON for each data connection in the app.config file.

The following code shows the content of a sample app.config file with two data connections:

   <?xml version="1.0" encoding="utf-8" ?>
   <configuration>
      <configSections>
      </configSections>
      <connectionStrings>
         <add name="WinApp1.Props.Settings.IBMCaptSQLConn1"
              providerName="IBM.Data.DB2" />
         <add name="WinApp1.Props.Settings.IBMCaptSQLConn2"
              providerName="IBM.Data.DB2" />
      </connectionStrings>
      <appSettings>
         <add key="WinApp1.Props.Settings.IBMCaptSQLConn1"
              value="Database=SAMPLE1;captureMode=ON;
              pureQueryXML=C:\temp\IBMCaptSQLConn1.capt;
              collection=jjones;rootPkgName=PKG1" />
         <add key="WinApp1.Props.Settings.IBMCaptSQLConn2"
              value="Database=SAMPLE2;User ID=testuser;
              Password=testpw;Server=testserver.com:50000;
              Persist Security Info=True;captureMode=ON;
              pureQueryXML=C:\temp\IBMCaptSQLConn2.capt;
              collection=testcollection;rootPkgName=PKG2" />
      </appSettings>
   </configuration>


See Also

Improving Performance and Security in .NET Applications with Static SQL | Using Static SQL in .NET Applications | Capturing SQL Statements in .NET Applications


.NET Development Forum   DB2 FAQs

© Copyright IBM Corporation 2002, 2019. All Rights Reserved.