/// <summary> /// Соединение с БД Master /// </summary> /// <param name="maxErrorCount"> /// Максимальное кол-во ошибок при соединении. /// После превышения заданного числа программа будет остановлена /// </param> public void ConnectMaster(int maxErrorCount) { if (_config.IsWindowsAuth(_config.MasterAuthorization)) { this._dbmMaster = new DBManager(this._config.MasterServerName, this._config.MasterDBName); } else { this._dbmMaster = new DBManager(this._config.MasterServerName, this._config.MasterDBUser, this._config.MasterDBPassword, this._config.MasterDBName); } if (maxErrorCount <= 0) { string errorMsg = String.Format("Reached the limit of connections to the database Master. DB server name: {0}. Auth type:{1}.", this._config.MasterServerName, this._config.MasterAuthorization); Console.WriteLine(errorMsg); _log.ErrorFormat(errorMsg); if (this._config.SendMail) { EMailSender smtp = new EMailSender(this._config.ProgMail, this._config.SmtpHost, this._config.SmtpUser, this._config.SmtpPassword, this._config.SmtpPort); smtp.SendMessage(errorMsg,this._config.AdminEMail); } System.Environment.Exit(0); } if (!this._dbmMaster.IsConnected()) { string errorMsg = String.Format("Unable to connect to database Master. DB server name: {0}. Auth type:{1}.", this._config.MasterServerName, this._config.MasterAuthorization); Console.WriteLine(errorMsg); _log.ErrorFormat(errorMsg); System.Threading.Thread.Sleep(this._config.SecondaryTimer); ConnectMaster(maxErrorCount-1); } }
/// <summary> /// Соединение с БД Slave /// </summary> /// <param name="maxErrorCount"> /// Максимальное кол-во ошибок при соединении. /// После превышения заданного числа программа будет остановлена /// </param> public void ConnectSlave(int maxErrorCount) { if (_config.IsWindowsAuth(_config.SlaveAuthorization)) { this._dbmSlave = new DBManager(this._config.SlaveServerName, this._config.SlaveDBName); } else { this._dbmSlave = new DBManager(this._config.SlaveServerName, this._config.SlaveDBUser, this._config.SlaveDBPassword, this._config.SlaveDBName); } if (maxErrorCount <= 0) { string errorMsg = String.Format("Reached the limit of connections to the database Slave. DB server name: {0}. Auth type:{1}.", this._config.SlaveServerName, this._config.SlaveAuthorization); Console.WriteLine(errorMsg); _log.ErrorFormat(errorMsg); if (this._config.SendMail) { EMailSender smtp = new EMailSender(this._config.ProgMail, this._config.SmtpHost, this._config.SmtpUser, this._config.SmtpPassword, this._config.SmtpPort); smtp.SendMessage(errorMsg, this._config.AdminEMail); } System.Environment.Exit(0); } if (!this._dbmSlave.IsConnected()) { string errorMsg = String.Format("Unable to connect to database Slave. DB server name: {0}. Auth type:{1}.", this._config.SlaveServerName, this._config.SlaveAuthorization); Console.WriteLine(errorMsg); _log.ErrorFormat(errorMsg); System.Threading.Thread.Sleep(this._config.SecondaryTimer); ConnectSlave(maxErrorCount - 1); } }