// *************************************************************** // Function: ConnectToDatabase.cpp // *************************************************************** #include "Main.h" //************************************ // Name: ConnectToDb // // Attempt to connect to the database (Internal only) // // Parameters: // // Return: // true - success // false - failure //************************************ bool ConnectToDb(){ //------------------------------------------------------------------ //try to establish a connection //------------------------------------------------------------------ gDatabase.Init(); if (!gDatabase.EstablishConnections(gDatabaseInfo.host, gDatabaseInfo.username, gDatabaseInfo.password, gDatabaseInfo.database_name, gDatabaseInfo.port, gServerConfig.maxPipes)) { gCoreLog.LOCATION; gCoreLog.error("Failed to connect to database! Host: %s User: %s Pass: %s DBName: %s, Port: %u, MaxPipes: %u", gDatabaseInfo.host, gDatabaseInfo.username, gDatabaseInfo.password, gDatabaseInfo.database_name, gDatabaseInfo.port, gServerConfig.maxPipes); return false; } return true; } //************************************ // Name: ConnectToDatabase // // Tries multiple times to connect to the database. // // Parameters: // // Return: // true - success // false - Could not establish a connection to the database //************************************ bool ConnectToDatabase() { int retry_counter=0; while(!ConnectToDb()) { gCoreLog.LOCATION; gCoreLog.warning("Trying again..."); if (gShuttingDown || retry_counter>=gServerConfig.maxRetryConnects) { gCoreLog.SectionFail(); return false; } retry_counter++; } gCoreLog.SectionOk(); return true; }