本文整理汇总了C#中System.Data.SqlClient.SqlConnection.RetrieveStatistics方法的典型用法代码示例。如果您正苦于以下问题:C# SqlConnection.RetrieveStatistics方法的具体用法?C# SqlConnection.RetrieveStatistics怎么用?C# SqlConnection.RetrieveStatistics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlConnection
的用法示例。
在下文中一共展示了SqlConnection.RetrieveStatistics方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoWork
public void DoWork()
{
using (SqlConnection conn = new SqlConnection(GlobalUtils.TopSecret.SqlServerCS))
using (SqlCommand command = new SqlCommand())
{
try
{
conn.Open();
conn.StatisticsEnabled = true;
command.Connection = conn;
}
catch (Exception e)
{
Console.Error.WriteLine(e.Message);
return;
}
try
{
using (SqlTransaction sqlTran = conn.BeginTransaction())
{
command.Transaction = sqlTran;
SqlDataReader reader;
List<string> commands = GetCommands(com);
foreach (string c in commands)
{
command.CommandText = c;
using (reader = command.ExecuteReader())
{
ShowResultSet(reader);
while (reader.NextResult())
ShowResultSet(reader);
}
}
var stats = conn.RetrieveStatistics();
using (TextWriter tw = new StreamWriter(path + ".stats"))
{
tw.WriteLine("Execution time: {0} sec, rows selected: {1}, rows affected: {2}",
Math.Round((double)(long)stats["ExecutionTime"] / 1000, 2),
stats["SelectRows"],
stats["IduRows"]);
}
}
}
catch (Exception e)
{
Console.Error.WriteLine(e.Message);
if (command != null)
command.Cancel();
}
}
}
示例2: AllAsync
public async Task<IEnumerable<TestData>> AllAsync()
{
List<TestData> results = new List<TestData>();
using (SqlConnection connection = new SqlConnection(AppConfiguration.ConnectionString))
{
bool useStaticCommand = false;
await connection.OpenAsync();
if(_useStats) connection.StatisticsEnabled = true;
SqlCommand command;
if (useStaticCommand)
{
command = staticCommand;
command.Connection = connection;
}
else
{
command = new SqlCommand(getAllCommandText, connection);
}
using (SqlDataReader reader = await command.ExecuteReaderAsync())
{
while (reader.Read())
{
var id = reader.GetString(0) ?? "";
var content = reader.GetString(1) ?? "";
results.Add(new TestData { Id = id, Content = content });
}
}
if (_useStats)
{
var stats = connection.RetrieveStatistics();
storeStatistics(stats);
}
}
return results;
}
示例3: Search
public static SalesOrderDetailList Search(string pcompany, out double mappingTiem, out double sqlCallTie, out Hashtable pRetrieveStatistics)
{
SqlConnection conn = new SqlConnection(GetCnnstring_App(pcompany));
conn.StatisticsEnabled = true;
SqlCommand cmd = new SqlCommand("SalesOrderDetail_s", conn);
cmd.CommandType = CommandType.StoredProcedure;
//cmd.Connection = conn;
//cmd.CommandText = "SalesOrderDetail_s";
SalesOrderDetailList list;
SalesOrderDetail sales;
Stopwatch watch = new Stopwatch();
try
{
conn.Open();
watch.Start();
IDataReader reader = cmd.ExecuteReader();
watch.Stop();
sqlCallTie = watch.Elapsed.TotalMilliseconds;
watch.Reset();
watch.Start();
#region DATA Mapping
list = new SalesOrderDetailList();
while (reader.Read())
{
sales = new SalesOrderDetail();
sales.CarrierTrackingNumber = reader["CarrierTrackingNumber"].ToString();
sales.LineTotal = Convert.ToInt32(reader["LineTotal"]);
sales.ModifiedDate = Convert.ToDateTime(reader["ModifiedDate"]);
sales.ProductID = Convert.ToInt32(reader.GetOrdinal("ProductID"));
sales.OrderQty = Convert.ToInt32(reader["OrderQty"]);
sales.rowguid = (Guid)reader["rowguid"];
sales.SalesOrderDetailID = Convert.ToInt32(reader["SalesOrderDetailID"]);
sales.SalesOrderID = Convert.ToInt32(reader["SalesOrderID"]);
sales.SpecialOfferID = Convert.ToInt32(reader["SpecialOfferID"]);
sales.UnitPrice = Convert.ToDouble(reader["UnitPrice"]);
sales.UnitPriceDiscount = Convert.ToDouble(reader["UnitPriceDiscount"]);
list.Add(sales);
}
reader.Close();
reader.Dispose();
#endregion
watch.Stop();
mappingTiem = watch.Elapsed.TotalMilliseconds;
//Recojo las estadísticas
pRetrieveStatistics = (Hashtable)conn.RetrieveStatistics();
return list;
}
catch (Exception ex)
{
throw Fwk.Exceptions.ExceptionHelper.ProcessException(ex);
}
}
示例4: CallScalarStoredProc
public async Task<int> CallScalarStoredProc()
{
int result = 0;
using (SqlConnection connection = new SqlConnection(AppConfiguration.ConnectionString))
{
string commandText = "EXEC [dbo].[TestProcedureThatDoNothing]";
SqlCommand command = new SqlCommand(commandText, connection);
if (_useStats) connection.StatisticsEnabled = true;
await connection.OpenAsync();
var procResult = await command.ExecuteScalarAsync();
if (procResult != null) result = (int) procResult;
if (_useStats)
{
var stats = connection.RetrieveStatistics();
storeStatistics(stats);
}
return result;
}
}
示例5: All
public IEnumerable<TestData> All()
{
List<TestData> results = new List<TestData>();
using (SqlConnection connection = new SqlConnection(AppConfiguration.ConnectionString))
{
try
{
SqlCommand command = new SqlCommand(getAllCommandText, connection);
if (_useStats) connection.StatisticsEnabled = true;
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
var id = reader.GetString(0) ?? "";
var content = reader.GetString(1) ?? "";
results.Add(new TestData { Id = id, Content = content });
}
}
if (_useStats)
{
var stats = connection.RetrieveStatistics();
storeStatistics(stats);
}
}
catch (SqlException ex)
{
Console.WriteLine(
"Error {0}: {1}",
ex.Number, ex.Message);
}
}
return results;
}