Skip to content

Commit

Permalink
Fixed a database connection leak issue
Browse files Browse the repository at this point in the history
  • Loading branch information
MythicalCuddles committed Feb 17, 2019
1 parent 7e29e1f commit 2c62cb6
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions DiscordBot/Database/DatabaseActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,9 @@ public static int ExecuteNonQueryCommand(string query, List<(string name, string
try
{
int rows = cmd.ExecuteNonQuery();
conn.Close();

new LogMessage(LogSeverity.Info, "Database Command",
"Command: " + cmd.CommandText + " | Rows affected: " + rows).PrintToConsole();
"Command: " + cmd.CommandText + " | Rows affected: " + rows).PrintToConsole();

return rows;
}
Expand All @@ -162,17 +161,37 @@ public static int ExecuteNonQueryCommand(string query, List<(string name, string
Console.WriteLine(e.Message);
throw;
}
finally
{
conn.Close();
}
}

public static MySqlDataReader ExecuteReader(string command)
{
MySqlConnection conn = OpenDatabaseConnection();
MySqlDataReader dr;

MySqlCommand cmd = new MySqlCommand
{
Connection = OpenDatabaseConnection(),
Connection = conn,
CommandText = command
};

try
{
dr = cmd.ExecuteReader();
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
finally
{
conn.Close();
}

MySqlDataReader dr = cmd.ExecuteReader();

return dr;
}
Expand Down

0 comments on commit 2c62cb6

Please sign in to comment.