
Originally Posted by
MoBaTeY
I find it odd that every time you make a database query, you connect to the database. Wouldn't this cause huge latency issues since every query will need to open a connection to the database? I don't also see where you ever disconnect from the database. Wouldn't you essentially flood the database by never closing the connections? Why isn't there a database manager which instantiates one connection to the database? I see this in every emulator out there. I remember a time at work when somebody did the exact same thing and I ended up fixing it by just instantiating it just once. The queries ended up being 300% faster at the end.

Code:
private readonly string _connectionStr;
private readonly IDatabaseClient _dbConnection;
public DatabaseManager(string ConnectionStr)
{
this._connectionStr = ConnectionStr;
_dbConnection = new DatabaseConnection(this._connectionStr);
_dbConnection.connect();
}
public bool IsConnected()
{
try
{
MySqlConnection Con = new MySqlConnection(this._connectionStr);
Con.Open();
MySqlCommand CMD = Con.CreateCommand();
CMD.CommandText = "SELECT 1+1";
CMD.ExecuteNonQuery();
CMD.Dispose();
Con.Close();
}
catch (MySqlException)
{
return false;
}
return true;
}
public IQueryAdapter GetQueryReactor()
{
try
{
return _dbConnection.GetQueryReactor();
}
catch (Exception e)
{
Logging.LogException(e.ToString());
return null;
}
}