Example #1
0
        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");
        }
Example #2
0
 public bool IsDatabaseConnectable()
 {
     try
     {
         DatabaseSession session = m_sessionFactory.GetDatabaseSession();
         return(session.CheckDatabaseConnection());
     }
     catch (DatabaseConnectionException e)
     {
     }
     return(false);
 }
Example #3
0
        public bool IsDatabaseConnectable(string ConnectionString)
        {
            DatabaseSession session = m_sessionFactory.GetDatabaseSession(ConnectionString);

            return(session.CheckDatabaseConnection());
        }