October 21, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

ADO.NET Trace Logging

  • January 22, 2008
  • By Bipin Joshi
  • Send Email »
  • More Articles »

The following figure shows a successful run of the above command. Make sure to replace the path of AdoNetDiag.mof file as per your installation.



Click here for a larger image.

To ensure that the ETW providers are enabled correctly, you can use the logman.exe command line tool. Issue the following command at the command prompt:

logman.exe list providers

The above command will display a list of ETW providers. The following figure shows a sample run of this command.



Click here for a larger image.

Out of the providers listed in the above figure, the following were registered because of the mofcomp.exe tool and AdoNetDiag.mof file.

Provider Description
ADONETDIAG.ETW This is a provider for events in the ETW adapter
System.Data.OracleClient.1 This is a provider for events in the System.Data.OracleClient.dll assembly
System.Data.SNI.1 This is a provider for the SQL Server Network Interface (SNI)-related events from System.Data.dll assembly
System.Data.1 This is a provider for events in the System.Data.dll assembly

Create a Trace Log by Using the Logman Tool

Now that you have published the required ETW providers, it's time to create a trace log. You do that with the help of the Logman command line tool. Before you use this tool, however, you need to create a text file that supplies information about the providers to be used. In the example, the text file will look like this:

"ADONETDIAG.ETW"        0x2     0x0     ADONETDIAG.ETW
"System.Data.1"         0x2     0x0     System.Data.1
"System.Data.SNI.1"     0x2     0x0     System.Data.SNI.1

The four columns indicate Provider, control bit, logging level, and provider name. The provider can be specified as a string value enclosed in double quotes or a GUID. The control bit is used to filter the trace. 0x2 means basic trace information. The logging level indicates what will be logged. The value of 0x0 means normal. Finally, the provider name indicates the name of the provider as expected by ETW.

Create the tab-delimited file above and save it as ProviderInfo.txt in a local folder on your machine.

Now, start a trace log by using logman tool as shown below:

logman.exe start MyTrace -pf providerinfo.txt
   -o MyTraceLog.etl -ets

In the above command:

  • start indicates that you want to start a new trace log named MyTrace
  • The -pf switch supplies a file containing the list of providers to be used. Remember to use the correct path of ProviderInfo.txt file as per your setup
  • The -o switch indicates the output file to store the log information. The log information is stored in binary format
  • The -ets switch indicates that the trace collection definition will be persisted in the system

Running ADO.NET Code

Now that you have enabled ADO.NET trace logging, it's time to test it. Create a new project of type "Console Application" using Visual Studio. In the Main() method, add the following code:

SqlConnection cnn;
SqlDataAdapter da;
SqlCommandBuilder builder;
DataSet ds;

string connstr = @"data source=.\sqlexpress;
   initial catalog=northwind;
integrated security=true";
cnn = new SqlConnection(connstr);
da = new SqlDataAdapter("select * from customers", cnn);
builder = new SqlCommandBuilder(da);
ds = new DataSet();
da.Fill(ds, "customers");
foreach (DataRow row in ds.Tables[0].Rows)
{
row["companyname"] = row["companyname"];
}
da.Update(ds, "customers");

The above code uses the Customers table of the Northwind database. It creates objects of the SqlCommection, SqlCommand, SqlDataAdapter, SqlCommandBuilder, and DataSet classes. It then fills up the DataSet with the help of SqlDataAdapter. The SqlCommandBuilder configures the SqlDataAdapter for INSERT, UPDATE, and DELETE operations. A for loop simply changes the CompanyName column of DataRow objects. Finally, the Update() method of SqlDataAdapter saves the changes back to the database.

After writing this code, run the application. This will cause some ADO.NET "activity" and thus some trace information will be logged.





Page 2 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel