Пример #1
0
        static void Main(string[] args)
        {
            const string   dataSource = "(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=JAVIER-HP)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=XEPDB1)))";
            OracleDatabase db         = new OracleDatabase();

            System.Console.WriteLine(db.IsConnected());
            try
            {
                db.Connect("risk", "ruffus", dataSource);
                db.ExecuteSQLCount("t_usuarios", "1=1");
                db.Disconnect();
            }
            catch (OracleDatabaseException)
            {
                System.Console.WriteLine("Hubo un error");
            }
        }
Пример #2
0
        /// <summary>
        /// connects the given database and returns it.
        /// </summary>
        /// <param name="database">The database to connect to.</param>
        /// <returns>The same database.</returns>
        protected OracleDatabase ConnectToDatabase(OracleDatabase database)
        {
            if (database == null || !database.IsConnected())
            {
                int count    = 0;
                int maxTries = 2;

                // trys 2 times
                while (count < maxTries)
                {
                    string host        = ConfigurationManager.AppSettings["DBHost"].ToString();
                    string port        = ConfigurationManager.AppSettings["DBPort"].ToString();
                    string serviceName = ConfigurationManager.AppSettings["DBServiceName"].ToString();
                    string userID      = ConfigurationManager.AppSettings["DBUserId"].ToString();
                    string password    = ConfigurationManager.AppSettings["DBPassword"].ToString();

                    Logger.Info($"Attempting to connect to host:{host}, port:{port}, service:{serviceName}, user:{userID}, password:{password}");

                    database = new OracleDatabase(host, port, serviceName, userID, password, Logger.GetLog4NetLogger());
                    database.Connect();
                    if (database.IsConnected())
                    {
                        Logger.Info($"Connected to database: {serviceName}");
                        break;
                    }

                    count++;
                }

                if (count > maxTries)
                {
                    Logger.Warn($"Failed to Connected to database");
                }
            }

            return(database);
        }