|
Este artículo se tradujo de forma manual. Mueva el puntero sobre las frases del artículo para ver el texto original.
|
Traducción
Original
|
Estadísticas de proveedor para SQL Server (ADO.NET)
Nota |
|---|
Recuperación de un valor
Nota |
|---|
Option Strict On Imports System Imports System.Collections Imports System.Data Imports System.Data.SqlClient Module Module1 Sub Main() Dim connectionString As String = GetConnectionString() Using awConnection As New SqlConnection(connectionString) ' StatisticsEnabled is False by default. ' It must be set to True to start the ' statistic collection process. awConnection.StatisticsEnabled = True Dim productSQL As String = "SELECT * FROM Production.Product" Dim productAdapter As _ New SqlDataAdapter(productSQL, awConnection) Dim awDataSet As New DataSet() awConnection.Open() productAdapter.Fill(awDataSet, "ProductTable") ' Retrieve the current statistics as ' a collection of values at this point ' and time. Dim currentStatistics As IDictionary = _ awConnection.RetrieveStatistics() Console.WriteLine("Total Counters: " & _ currentStatistics.Count.ToString()) Console.WriteLine() ' Retrieve a few individual values ' related to the previous command. Dim bytesReceived As Long = _ CLng(currentStatistics.Item("BytesReceived")) Dim bytesSent As Long = _ CLng(currentStatistics.Item("BytesSent")) Dim selectCount As Long = _ CLng(currentStatistics.Item("SelectCount")) Dim selectRows As Long = _ CLng(currentStatistics.Item("SelectRows")) Console.WriteLine("BytesReceived: " & bytesReceived.ToString()) Console.WriteLine("BytesSent: " & bytesSent.ToString()) Console.WriteLine("SelectCount: " & selectCount.ToString()) Console.WriteLine("SelectRows: " & selectRows.ToString()) Console.WriteLine() Console.WriteLine("Press any key to continue") Console.ReadLine() End Using End Sub Function GetConnectionString() As String ' To avoid storing the connection string in your code, ' you can retrive it from a configuration file. Return "Data Source=localhost;Integrated Security=SSPI;" & _ "Initial Catalog=AdventureWorks" End Function End Module
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
namespace CS_Stats_Console_GetValue
{
class Program
{
static void Main(string[] args)
{
string connectionString = GetConnectionString();
using (SqlConnection awConnection =
new SqlConnection(connectionString))
{
// StatisticsEnabled is False by default.
// It must be set to True to start the
// statistic collection process.
awConnection.StatisticsEnabled = true;
string productSQL = "SELECT * FROM Production.Product";
SqlDataAdapter productAdapter =
new SqlDataAdapter(productSQL, awConnection);
DataSet awDataSet = new DataSet();
awConnection.Open();
productAdapter.Fill(awDataSet, "ProductTable");
// Retrieve the current statistics as
// a collection of values at this point
// and time.
IDictionary currentStatistics =
awConnection.RetrieveStatistics();
Console.WriteLine("Total Counters: " +
currentStatistics.Count.ToString());
Console.WriteLine();
// Retrieve a few individual values
// related to the previous command.
long bytesReceived =
(long) currentStatistics["BytesReceived"];
long bytesSent =
(long) currentStatistics["BytesSent"];
long selectCount =
(long) currentStatistics["SelectCount"];
long selectRows =
(long) currentStatistics["SelectRows"];
Console.WriteLine("BytesReceived: " +
bytesReceived.ToString());
Console.WriteLine("BytesSent: " +
bytesSent.ToString());
Console.WriteLine("SelectCount: " +
selectCount.ToString());
Console.WriteLine("SelectRows: " +
selectRows.ToString());
Console.WriteLine();
Console.WriteLine("Press any key to continue");
Console.ReadLine();
}
}
private static string GetConnectionString()
{
// To avoid storing the connection string in your code,
// you can retrive it from a configuration file.
return "Data Source=localhost;Integrated Security=SSPI;" +
"Initial Catalog=AdventureWorks";
}
}
}
Recuperación de todos los valores
Nota |
|---|
using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; namespace CS_Stats_Console_GetAll { class Program { static void Main(string[] args) { string connectionString = GetConnectionString(); using (SqlConnection awConnection = new SqlConnection(connectionString)) { // StatisticsEnabled is False by default. // It must be set to True to start the // statistic collection process. awConnection.StatisticsEnabled = true; string productSQL = "SELECT * FROM Production.Product"; SqlDataAdapter productAdapter = new SqlDataAdapter(productSQL, awConnection); DataSet awDataSet = new DataSet(); awConnection.Open(); productAdapter.Fill(awDataSet, "ProductTable"); // Retrieve the current statistics as // a collection of values at this point // and time. IDictionary currentStatistics = awConnection.RetrieveStatistics(); Console.WriteLine("Total Counters: " + currentStatistics.Count.ToString()); Console.WriteLine(); Console.WriteLine("Key Name and Value"); // Note the entries are unsorted. foreach (DictionaryEntry entry in currentStatistics) { Console.WriteLine(entry.Key.ToString() + ": " + entry.Value.ToString()); } Console.WriteLine(); Console.WriteLine("Press any key to continue"); Console.ReadLine(); } } private static string GetConnectionString() { // To avoid storing the connection string in your code, // you can retrive it from a configuration file. return "Data Source=localhost;Integrated Security=SSPI;" + "Initial Catalog=AdventureWorks"; } } }
Nota