当前位置: 首页>>代码示例>>C#>>正文


C# SqlConnection.RetrieveStatistics方法代码示例

本文整理汇总了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();
                }
            }
        }
开发者ID:ren85,项目名称:rextester_win,代码行数:52,代码来源:Program.cs

示例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;
        }
开发者ID:rhwy,项目名称:AspNetSiteTest,代码行数:37,代码来源:RawSqlTestRepo.cs

示例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);
            }
        }
开发者ID:gpanayir,项目名称:sffwk,代码行数:67,代码来源:SalesDAC.cs

示例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;
            }
        }
开发者ID:rhwy,项目名称:AspNetSiteTest,代码行数:21,代码来源:RawSqlTestRepo.cs

示例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;
 }
开发者ID:rhwy,项目名称:AspNetSiteTest,代码行数:36,代码来源:RawSqlTestRepo.cs


注:本文中的System.Data.SqlClient.SqlConnection.RetrieveStatistics方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。