using System; using System.Data; using System.Data.Common; using System.Data.OracleClient; namespace STMes.DataProvider { /// /// Implements access to the Data Provider for Oracle. /// /// /// See the method to find an example. /// /// AddDataManager Method public class OracleDataProvider : IDataProvider { private CoreWriteLogFile cwl = new CoreWriteLogFile(); /// /// Creates the database connection object. /// /// /// See the method to find an example. /// /// AddDataManager Method /// The database connection object. IDbConnection IDataProvider.CreateConnectionObject() { OracleConnection conn = new OracleConnection(); return conn; } IDbConnection IDataProvider.CreateConnectionObject(string connectionString) { OracleConnection conn = new OracleConnection(connectionString); return conn; } /// /// Creates the data adapter object. /// /// /// See the method to find an example. /// /// AddDataManager Method /// A data adapter object. DbDataAdapter IDataProvider.CreateDataAdapterObject() { return new OracleDataAdapter(); } /// /// Populates the specified IDbCommand object's Parameters collection with /// parameter information for the stored procedure specified in the IDbCommand. /// /// /// See the method to find an example. /// /// AddDataManager Method /// The IDbCommand referencing the stored procedure for which the parameter information is to be derived. The derived parameters will be populated into the Parameters of this command. void IDataProvider.DeriveParameters(IDbCommand command) { OracleCommandBuilder.DeriveParameters((OracleCommand)command); } /// /// Returns connection type. /// /// /// See the method to find an example. /// /// AddDataManager Method /// An instance of the class. public Type ConnectionType { get { return typeof(OracleConnection); } } /// /// Returns the data provider name. /// /// /// See the method to find an example. /// /// AddDataProvider Method /// Data provider name. public string Name { get { return "Oracle"; } } /// /// /// /// public IDbDataParameter CreateDataParameter() { // TODO: Ìí¼Ó OracleDataProvider.CreateDataParameter ʵÏÖ return new OracleParameter(); } /// /// /// /// /// public Object CreateCommandBuilder(DbDataAdapter da) { return new OracleCommandBuilder(da as OracleDataAdapter) as object; } /// /// Test Connection Info(ORACLE) /// /// Test Connection Object /// Test Result public bool Ping(ref IDbConnection db) { OracleDataReader read = null; try { using (OracleCommand cmd = new OracleCommand("SELECT 1 FROM DUAL", (OracleConnection)db)) { read = cmd.ExecuteReader(); } return true; } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { if (read != null) read.Dispose(); } return false; } public int GetSID(ref IDbConnection db) { //OracleDataReader read = null; //try //{ // int sid = -1; // using (OracleCommand cmd = new OracleCommand("SELECT SID FROM SYS.V_$MYSTAT@XGCXMES WHERE ROWNUM =1", (OracleConnection)db)) // { // read = cmd.ExecuteReader(); // while (read.Read()) // { // sid = Convert.ToInt32(read.GetValue(0)); // read.Close(); // return sid; // } // } //} //catch (Exception ex) //{ // cwl.WriteLog(ex.Message, LogInfoLevel.Error, "GetSID", "ORACLE"); //} //finally //{ // if (read != null) read.Dispose(); //} return -1; } } }