コード例 #1
0
        private void SelectTables()
        {
            var profiler        = MiniProfiler.Current;
            var bareFactory     = DbProviderFactories.GetFactory("System.Data.SqlClient");
            var providerFactory = new ProfiledDbProviderFactory(profiler, bareFactory);

            var connStr = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;

            var bareConnection = new SqlConnection(connStr);

            var profiledConnection = new ProfiledDbConnection(bareConnection, profiler);

            var profiledCommand = providerFactory.CreateCommand();

            profiledCommand.Connection  = profiledConnection;
            profiledCommand.CommandText = "SELECT * FROM sys.tables";

            using (profiler.Step("Open Connection"))
            {
                profiledConnection.Open();
            }

            using (profiler.Step("ExecuteNonQuery"))
            {
                profiledCommand.ExecuteNonQuery();
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            // Setup for console application example.
            MiniProfiler.Settings.Storage          = new HttpRuntimeCacheStorage(TimeSpan.FromHours(1));
            MiniProfiler.Settings.ProfilerProvider = new SingletonProfilerProvider();

            var defaultFactory = DbProviderFactories.GetFactory("System.Data.SqlClient");

            var factory = new ProfiledDbProviderFactory(defaultFactory);

            try
            {
                DoStuff(factory);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
            }

            var workedaroundFactory = new ProfiledDbProviderFactoryAlwaysProfiled(defaultFactory);

            DoStuff(workedaroundFactory);
        }