GetDBConnection(string host, int port, String sid, String user, String password) { MyConsole.Info("Oracle: getting connection"); // 'Connection string' to connect directly to Oracle. string connString = "Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = " + host + ")(PORT = " + port + "))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = " + sid + ")));Password="******";User ID=" + user; OracleConnection conn = new OracleConnection(); conn.ConnectionString = connString; return(conn); }
public void Process() { while (true) { Thread.Sleep(100); try { if (conn.State == ConnectionState.Open || conn.State == ConnectionState.Executing || conn.State == ConnectionState.Fetching) { continue; } conn.Open(); MyConsole.Info("Oracle: reconnected"); } catch (Exception) { Thread.Sleep(1000); } } }
private static void Conn_StateChange(object sender, StateChangeEventArgs e) { MyConsole.Info(e.CurrentState.ToString()); if (e.CurrentState == ConnectionState.Broken || e.CurrentState == ConnectionState.Closed) { MyConsole.Error("Oracle: connection lost"); try { OracleConnection conn = (OracleConnection)sender; conn.Open(); } catch (Exception ex) { MyConsole.Error(ex.Message); return; } MyConsole.Info("Oracle: connection successful"); } }
static void Main(string[] args) { //Переменные программы int webServerPort = 8081; string oracleHost = ""; int oraclePort = 1521; string oracleSid = "hydra"; string oracleUser = "******"; string oraclePassword = ""; //Переменный класса OracleConnection conn; HttpServer httpServer; Thread threadWD; Thread thread; log4net.Config.XmlConfigurator.Configure(); var route_config = new List <Route>() { new Route { Name = "Run query", UrlRegex = @"^/Query/(.*)$", Method = "POST", Callable = RunQuery }, new Route { Name = "Run procedure", UrlRegex = @"^/Procedure/(.*)$", Method = "POST", Callable = RunProcedure }, }; conn = DBUtils.GetDBConnection(oracleHost, oraclePort, oracleSid, oracleUser, oraclePassword); MyConsole.Info("Oracle: get connection: " + conn); try { conn.Open(); MyConsole.Info("Oracle: connection successful"); MyConsole.Info("Hydra billing: init start"); HydraBilling.Context.Init(conn); MyConsole.Info("Hydra billing: init complite"); conn.Close(); } catch (Exception ex) { MyConsole.Error(ex.Message); Console.Read(); return; } MyConsole.Info("Web server: starting"); httpServer = new HttpServer(webServerPort, route_config); thread = new Thread(new ThreadStart(httpServer.Listen)); thread.Start(); Thread.Sleep(100); if (!thread.IsAlive) { MyConsole.Error(httpServer.error); Console.Read(); return; } MyConsole.Info("Web server: started"); /*using (DbDataReader reader = cmd.ExecuteReader()) * { * if (reader.HasRows) * { * * while (reader.Read()) * { * // Get index of Column Emp_ID in query statement. * int empIdIndex = reader.GetOrdinal("Emp_Id"); // 0 * * * long empId = Convert.ToInt64(reader.GetValue(0)); * * // Index of Emp_ID = 1 * string empNo = reader.GetString(1); * int empNameIndex = reader.GetOrdinal("Emp_Name");// 2 * string empName = reader.GetString(empNameIndex); * * // Index of column Mng_Id. * // Chỉ số (index) của cột Mng_Id trong câu lệnh SQL. * int mngIdIndex = reader.GetOrdinal("Mng_Id"); * * long? mngId = null; * * if (!reader.IsDBNull(mngIdIndex)) * { * mngId = Convert.ToInt64(reader.GetValue(mngIdIndex)); * } * Console.WriteLine("--------------------"); * Console.WriteLine("empIdIndex:" + empIdIndex); * Console.WriteLine("EmpId:" + empId); * Console.WriteLine("EmpNo:" + empNo); * Console.WriteLine("EmpName:" + empName); * Console.WriteLine("MngId:" + mngId); * } * } * }*/ /*conn.Open(); * using (DbDataReader dbReader = DBOracleUtils.OracleQuery("select VC_SUBJ_NAME from SI_V_USERS", conn)) * { * while (dbReader.Read()) * { * int empNameIndex = dbReader.GetOrdinal("VC_SUBJ_NAME");// 2 * string empName = dbReader.GetString(empNameIndex); * Console.WriteLine("VC_SUBJ_NAME:" + empName); * } * } * conn.Close();*/ }