@@ -14,26 +14,12 @@ public sealed class Database
1414
1515 private Database ( ) { }
1616
17- public void Initialize ( string server , string database , string userId , string password , int port = 3306 , string sslMode = "None" , bool usePooling = true , uint minPoolSize = 10 , uint maxPoolSize = 50 )
17+ public void Initialize ( string server , string database , string userId , string password , int port = 3306 , string sslMode = "None" )
1818 {
19- connectionString = BuildConnectionString ( server , database , userId , password , port , sslMode , usePooling , minPoolSize , maxPoolSize ) ;
19+ connectionString = BuildConnectionString ( server , database , userId , password , port , sslMode ) ;
2020 }
2121
22- public void AdjustDatabasePooling ( )
23- {
24- if ( connectionString == null )
25- throw new InvalidOperationException ( "Database has not been initialized" ) ;
26-
27- var builder = new MySqlConnectionStringBuilder ( connectionString )
28- {
29- MinimumPoolSize = ( uint ) Math . Max ( 5 , Server . MaxPlayers / 2.5 ) ,
30- MaximumPoolSize = ( uint ) Math . Max ( 10 , Server . MaxPlayers + 1 ) ,
31- } ;
32-
33- connectionString = builder . ConnectionString ;
34- }
35-
36- private static string BuildConnectionString ( string server , string database , string userId , string password , int port , string sslMode , bool usePooling , uint minPoolSize , uint maxPoolSize )
22+ private static string BuildConnectionString ( string server , string database , string userId , string password , int port , string sslMode )
3723 {
3824 var builder = new MySqlConnectionStringBuilder
3925 {
@@ -43,9 +29,6 @@ private static string BuildConnectionString(string server, string database, stri
4329 Password = password ,
4430 Port = ( uint ) port ,
4531 SslMode = Enum . Parse < MySqlSslMode > ( sslMode , true ) ,
46- Pooling = usePooling ,
47- MinimumPoolSize = 10 ,
48- MaximumPoolSize = 24 ,
4932 } ;
5033
5134 return builder . ConnectionString ;
@@ -79,12 +62,16 @@ public async Task ExecuteNonQueryAsync(string query, params MySqlParameter[] par
7962
8063 public async Task < MySqlDataReader > ExecuteReaderAsync ( string query , params MySqlParameter [ ] parameters )
8164 {
82- var connection = new MySqlConnection ( connectionString ) ;
83- await connection . OpenAsync ( ) ;
65+ using ( var connection = new MySqlConnection ( connectionString ) )
66+ {
67+ await connection . OpenAsync ( ) ;
8468
85- var command = new MySqlCommand ( query , connection ) ;
86- command . Parameters . AddRange ( parameters ) ;
87- return await command . ExecuteReaderAsync ( CommandBehavior . CloseConnection ) ;
69+ using ( var command = new MySqlCommand ( query , connection ) )
70+ {
71+ command . Parameters . AddRange ( parameters ) ;
72+ return await command . ExecuteReaderAsync ( CommandBehavior . CloseConnection ) ;
73+ }
74+ }
8875 }
8976
9077 public async Task ExecuteWithTransactionAsync ( Func < MySqlConnection , MySqlTransaction , Task > executeActions )
0 commit comments