-
-
Save nvivo/3fc457baa29870c3395d46ecae4da2d2 to your computer and use it in GitHub Desktop.
Reproduce issue https://github.com/mysql-net/MySqlConnector/issues/305
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net47</TargetFramework> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="dapper" Version="1.50.2" /> | |
<PackageReference Include="mysqlconnector" Version="0.24.1" /> | |
</ItemGroup> | |
<ItemGroup> | |
<Reference Include="Microsoft.CSharp" /> | |
</ItemGroup> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Dapper; | |
using MySql.Data.MySqlClient; | |
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace ConsoleApp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var builder = new MySqlConnectionStringBuilder | |
{ | |
Server = "localhost", | |
UserID = "root", | |
Password = "", | |
Database = "information_schema", | |
MaximumPoolSize = 50, | |
ConnectionIdleTimeout = 10, | |
AllowUserVariables = false | |
}; | |
var cs = builder.ConnectionString; | |
Task.Run(async () => | |
{ | |
while (true) | |
{ | |
try | |
{ | |
using (var cn = new MySqlConnection(cs)) | |
{ | |
await cn.OpenAsync(); | |
await cn.QueryFirstAsync<int>("SET @test = 1; SELECT @test;"); | |
} | |
} | |
catch | |
{ } | |
} | |
}); | |
using (var cn = new MySqlConnection(cs)) | |
{ | |
cn.Open(); | |
while (true) | |
{ | |
var o = cn.QueryFirst("select max(time) as MaxSleepTime, count(*) as SleepingConnections from processlist where db = 'information_schema' and command = 'Sleep'"); | |
Console.WriteLine($"Sleeping Connections: {(int) o.SleepingConnections}, Max Sleep Time: {(int) o.MaxSleepTime}"); | |
Thread.Sleep(1000); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment