Mysql
 sql >> Datenbank >  >> RDS >> Mysql

So überwachen Sie das Verbindungspooling für .NET MySQL Data Connector in IIS

Ich habe zwei Dinge getan, um bei diesem Problem zu helfen.

Der vollständige Code, den ich verwende, ist:

string path = u.MapPath("~/bin/MySql.Data.dll");
Assembly ms = Assembly.LoadFrom(path);
Type type = ms.GetType("MySql.Data.MySqlClient.MySqlPoolManager");
MethodInfo mi = type.GetMethod("GetPool", BindingFlags.Static | BindingFlags.Public);

var pool = mi.Invoke(null, new object[] { new MySqlConnectionStringBuilder(ConnectionString) });
Type mip = ms.GetType("MySql.Data.MySqlClient.MySqlPool");
MemberInfo[] mei1 = mip.GetMember("inUsePool", BindingFlags.NonPublic);
totalAvailable = (int)pool.GetType().InvokeMember("available", BindingFlags.GetField | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, null, pool, new object[] { });
var o = pool.GetType().InvokeMember("inUsePool", BindingFlags.GetField | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, pool, new object[] { });
var o1 = pool.GetType().InvokeMember("idlePool", BindingFlags.GetField | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, pool, new object[] { });
inUseCount = (int)o.GetType().InvokeMember("Count", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public, null, o, null);
idleCount = (int)o1.GetType().InvokeMember("Count", BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public, null, o1, null);