How to monitor connection pooling for .NET MySQL Data Connector in IIS

后端 未结 1 454
忘了有多久
忘了有多久 2021-01-16 17:50

I have googled a fair bit on this, but not been able to find an exact answer. We are seeing the following errors in our logs:

Timeout expired. The ti

相关标签:
1条回答
  • 2021-01-16 18:40

    I have done two things to help with this problem.

    • Upgraded the MySQL drivers.
    • Used code from How to query the current size of the MySQL's .Net connector's connection pool? to create a web page to monitor the state of the connection pool on my server.

    The full code I use is:

    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);
    
    0 讨论(0)
提交回复
热议问题