39130

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

Question:

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:

<blockquote>

Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. Stack Trace: at MySql.Data.MySqlClient.MySqlPool.GetConnection() at MySql.Data.MySqlClient.MySqlConnection.Open()

</blockquote>

I can monitor client connections on the MySQL server (and they appear fine), but the error is occurring in the ASP application. There is nothing obvious in my code, so I wanted to monitor the connection pool and see what was going on. I want to add MySQL performance counters into performance monitor in windows. But the only MySQL counters I see are HardProcedureQueries and SoftProcedureQueries. SQL Server and Oracle have a load related to Connection pooling and other items of interest. There have been some unanswered articles in different forums asking the same thing.

So, how do people out there monitor ASP .NET MySQl connection pool counters in IIS on Windows?

We're using .NET 4 on IIS 7.5 on Windows Server 2008

Answer1:

I have done two things to help with this problem.

<ul><li>Upgraded the MySQL drivers.</li> <li>Used code from <a href="https://stackoverflow.com/questions/14963556/how-to-query-the-current-size-of-the-mysqls-net-connectors-connection-pool" rel="nofollow">How to query the current size of the MySQL's .Net connector's connection pool?</a> to create a web page to monitor the state of the connection pool on my server.</li> </ul>

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);

Recommend

  • Can't connect Entity Framework to local SQL Server Express
  • inserting items in list in mongodb document
  • Sympy: working with equalities manually
  • Mongodb update() vs. findAndModify() performace
  • UIBarButtonItem's action is not called when in a view with a UIGestureRecognizer
  • C++/CLI Thread synchronization including managed and unmanaged code
  • It is possible use the same sql azure instance from two different cloud service of two different sub
  • How to open multiple instances of a program in Linux
  • Manually Timing out a C# Thread
  • Efficient User-Agent Regex to find Safari in Python
  • Is it possible to get the word under the mouse cursor in a ``?
  • C# List of Panels
  • using System.Speech.Synthesis with Windows10 universal app (XAML-C#)
  • How to return DataSet (xsd) in WCF
  • Bash if statement with multiple conditions
  • Spring Cloud Microservice Architecture Confusion
  • presentShareDialogWithParams posts to FB wall, but callback handler results say error
  • Alternative to overridePendingTransition() - Android
  • Transactional Create with Validation in ServiceStack Redis Client
  • Ionic 2 storage is not cleaning up on uninstall - Only for signed APK
  • Custom validator control occupying space even though display set to dynamic
  • Row Count Is Returning the incorrect number using RaptureXML
  • Handling un-mapped Rest path
  • Is my CUDA kernel really runs on device or is being mistekenly executed by host in emulation?
  • PHP - How to update data to MySQL when click a radio button
  • C# - Serializing and deserializing static member
  • Sending data from AppleScript to FileMaker records
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • How to include full .NET prerequisite for Wix Burn installer
  • json Serialization in asp
  • Acquiring multiple attributes from .xml file in c#
  • CSS Applying specific rule for a specific monitor resolution with only CSS is posible?
  • Angular 2 constructor injection vs direct access
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Java static initializers and reflection
  • Android Google Maps API OnLocationChanged only called once
  • How can I remove ASP.NET Designer.cs files?
  • Is it possible to post an object from jquery to bottle.py?
  • UserPrincipal.Current returns apppool on IIS
  • java string with new operator and a literal