public DatabaseSession GetDatabaseSession() { string FUNCTION_NAME = "GetDatabaseSession"; LogHelperCli.GetInstance().Log_Generic(CLASS_NAME + "." + FUNCTION_NAME, LogHelperCli.GetInstance().GetLineNumber(), EDebugLevelManaged.DebugInfo, "Function Entered"); bool bConnected = false; int nTrytimes = 0; while (!bConnected && nTrytimes++ <= MAX_TIMES) { DatabaseSession currentSession = m_sessionStore.GetCurrentSession(); if (currentSession != null && currentSession.IsTransactionOpen()) { LogHelperCli.GetInstance().Log_Generic(CLASS_NAME + "." + FUNCTION_NAME, LogHelperCli.GetInstance().GetLineNumber(), EDebugLevelManaged.DebugInfo, "Transaction open in current Session"); if (currentSession.CheckDatabaseConnection()) { LogHelperCli.GetInstance().Log_Generic(CLASS_NAME + "." + FUNCTION_NAME, LogHelperCli.GetInstance().GetLineNumber(), EDebugLevelManaged.DebugInfo, "Function Exited"); return(currentSession); } } else { string connectionString = DBConnectionStrings.GetInstance().GetConnectionString(); if (connectionString != null) { DatabaseSession session = m_sessionStore.GetSession(connectionString); if (session == null) { CreateDatabaseSession(connectionString); session = m_sessionStore.GetSession(connectionString); } if (session.CheckDatabaseConnection()) { /*if (m_DBSwitched.Length != 0 && (m_DBSwitched == connectionString)) * { * m_DBSwitched = ""; * }*/ m_sessionStore.StoreCurrentSession(session); LogHelperCli.GetInstance().Log_Generic(CLASS_NAME + "." + FUNCTION_NAME, LogHelperCli.GetInstance().GetLineNumber(), EDebugLevelManaged.DebugInfo, "Function Exited"); return(session); } else { // m_DBSwitched = connectionString; // DBConnectionStrings.GetInstance().UpdateDBStatus(connectionString, DBStatus.DB_OFFLINE); } } } } throw new DatabaseConnectionException("No Database Connection"); }
public static void ReleaseInstance() { string FUNCTION_NAME = "ReleaseInstance"; lock (s_Singleton) { if (s_DBConnectionStrings != null) { s_DBConnectionStrings = null; } } }
public static DBConnectionStrings GetInstance() { string FUNCTION_NAME = "GetInstance"; lock (s_Singleton) { if (s_DBConnectionStrings == null) { s_DBConnectionStrings = new DBConnectionStrings(); } } return(s_DBConnectionStrings); }