Use another way to connect to database. (#3)
* Use another way to connect to database. Actual way crash if mysql user doesn't have for example the password. * remove tabs -> spaces
This commit is contained in:
@@ -35,14 +35,16 @@ namespace Framework.Database
|
||||
bool updatesEnabled = database.IsAutoUpdateEnabled(_updateFlags);
|
||||
_open.Add(() =>
|
||||
{
|
||||
string dbString = ConfigMgr.GetDefaultValue(name + "DatabaseInfo", "");
|
||||
if (string.IsNullOrEmpty(dbString))
|
||||
{
|
||||
Log.outError(LogFilter.ServerLoading, "Database {0} not specified in configuration file!", name);
|
||||
return false;
|
||||
}
|
||||
ConnectionObject co = new ConnectionObject
|
||||
{
|
||||
Database = ConfigMgr.GetDefaultValue(name + "DatabaseInfo.Database", ""),
|
||||
Host = ConfigMgr.GetDefaultValue(name + "DatabaseInfo.Host", ""),
|
||||
Password = ConfigMgr.GetDefaultValue(name + "DatabaseInfo.Password", ""),
|
||||
Port = ConfigMgr.GetDefaultValue(name + "DatabaseInfo.Port", ""),
|
||||
Username = ConfigMgr.GetDefaultValue(name + "DatabaseInfo.Username", "")
|
||||
};
|
||||
|
||||
var error = database.Initialize(dbString);
|
||||
var error = database.Initialize(co);
|
||||
if (error != MySqlErrorCode.None)
|
||||
{
|
||||
// Database does not exist
|
||||
@@ -57,7 +59,7 @@ namespace Framework.Database
|
||||
Log.outInfo(LogFilter.ServerLoading, "Creating database \"{0}\"...", name);
|
||||
string sqlString = string.Format("CREATE DATABASE `{0}` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci", name);
|
||||
// Try to create the database and connect again if auto setup is enabled
|
||||
if (database.Apply(sqlString) && database.Initialize(dbString) == MySqlErrorCode.None)
|
||||
if (database.Apply(sqlString) && database.Initialize(co) == MySqlErrorCode.None)
|
||||
error = MySqlErrorCode.None;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user