forked from teddymacn/MySqlWebProfilingDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Default.aspx.cs
65 lines (58 loc) · 1.45 KB
/
Default.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Web;
using System.Web.UI;
using MySql.Data.MySqlClient;
using EF.Diagnostics.Profiling;
using EF.Diagnostics.Profiling.Data;
namespace MySqlWebProfilingDemo
{
public partial class Default : Page
{
protected override void OnLoad (EventArgs e)
{
if (!this.IsPostBack)
{
using (var conn = CreateConnection())
{
conn.Open();
using (var cmd = conn.CreateCommand())
{
cmd.Connection = conn;
// warm up
cmd.CommandText = "SELECT 1 FROM world.city limit 1;";
cmd.ExecuteScalar();
// load actual data
cmd.CommandText = "SELECT * FROM world.city limit 5000;";
using (var sda = CreateDataAdapter())
{
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
}
}
private DbConnection CreateConnection()
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
var mySqlConn = new MySqlConnection(constr);
var profilingSession = ProfilingSession.Current;
return profilingSession == null ?
(DbConnection)mySqlConn
:
new ProfiledDbConnection(mySqlConn, new DbProfiler(profilingSession.Profiler));
}
private DbDataAdapter CreateDataAdapter()
{
return new MySqlDataAdapter();
}
}
}