ODPDataProvider.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. using System;
  2. using System.Data;
  3. using System.Data.Common;
  4. using Oracle.DataAccess.Client;
  5. namespace STMes.DataProvider
  6. {
  7. /// <summary>
  8. /// Implements access to the Data Provider for SQL Server.
  9. /// </summary>
  10. /// <remarks>
  11. /// See the <see cref="DbManager.AddDataProvider"/> method to find an example.
  12. /// </remarks>
  13. /// <seealso cref="DbManager.AddDataProvider">AddDataManager Method</seealso>
  14. public class ODPDataProvider : IDataProvider
  15. {
  16. private CoreWriteLogFile cwl = new CoreWriteLogFile();
  17. /// <summary>
  18. /// Creates the database connection object.
  19. /// </summary>
  20. /// <remarks>
  21. /// See the <see cref="DbManager.AddDataProvider"/> method to find an example.
  22. /// </remarks>
  23. /// <seealso cref="DbManager.AddDataProvider">AddDataManager Method</seealso>
  24. /// <returns>The database connection object.</returns>
  25. IDbConnection IDataProvider.CreateConnectionObject()
  26. {
  27. return new OracleConnection();
  28. }
  29. IDbConnection IDataProvider.CreateConnectionObject(string connectionString)
  30. {
  31. OracleConnection conn = new OracleConnection(connectionString);
  32. return conn;
  33. }
  34. /// <summary>
  35. /// Creates the data adapter object.
  36. /// </summary>
  37. /// <remarks>
  38. /// See the <see cref="DbManager.AddDataProvider"/> method to find an example.
  39. /// </remarks>
  40. /// <seealso cref="DbManager.AddDataProvider">AddDataManager Method</seealso>
  41. /// <returns>A data adapter object.</returns>
  42. DbDataAdapter IDataProvider.CreateDataAdapterObject()
  43. {
  44. return new OracleDataAdapter();
  45. }
  46. /// <summary>
  47. /// Populates the specified IDbCommand object's Parameters collection with
  48. /// parameter information for the stored procedure specified in the IDbCommand.
  49. /// </summary>
  50. /// <remarks>
  51. /// See the <see cref="DbManager.AddDataProvider"/> method to find an example.
  52. /// </remarks>
  53. /// <seealso cref="DbManager.AddDataProvider">AddDataManager Method</seealso>
  54. /// <param name="command">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.</param>
  55. void IDataProvider.DeriveParameters(IDbCommand command)
  56. {
  57. //OracleCommandBuilder.DeriveParameters((OracleCommand)command);
  58. return;
  59. }
  60. /// <summary>
  61. /// Returns connection type.
  62. /// </summary>
  63. /// <remarks>
  64. /// See the <see cref="DbManager.AddDataProvider"/> method to find an example.
  65. /// </remarks>
  66. /// <seealso cref="DbManager.AddDataProvider">AddDataManager Method</seealso>
  67. /// <value>An instance of the <see cref="Type"/> class.</value>
  68. public Type ConnectionType
  69. {
  70. get
  71. {
  72. return typeof(OracleConnection);
  73. }
  74. }
  75. /// <summary>
  76. /// Returns the data provider name.
  77. /// </summary>
  78. /// <remarks>
  79. /// See the <see cref="DbManager.AddDataProvider"/> method to find an example.
  80. /// </remarks>
  81. /// <seealso cref="DbManager.AddDataProvider">AddDataProvider Method</seealso>
  82. /// <value>Data provider name.</value>
  83. public string Name
  84. {
  85. get
  86. {
  87. return "ODP";
  88. }
  89. }
  90. /// <summary>
  91. ///
  92. /// </summary>
  93. /// <returns></returns>
  94. public IDbDataParameter CreateDataParameter()
  95. {
  96. // TODO: Ìí¼Ó SqlDataProvider.CreateDataParameter ʵÏÖ
  97. return new OracleParameter();
  98. }
  99. /// <summary>
  100. ///
  101. /// </summary>
  102. /// <param name="da"></param>
  103. /// <returns></returns>
  104. public Object CreateCommandBuilder(DbDataAdapter da)
  105. {
  106. return new OracleCommandBuilder(da as OracleDataAdapter) as object;
  107. }
  108. /// <summary>
  109. /// Test Connection Info(ODP)
  110. /// </summary>
  111. /// <param name="db">Test Connection Object</param>
  112. /// <returns>Test Result</returns>
  113. public bool Ping(ref IDbConnection db)
  114. {
  115. OracleDataReader read = null;
  116. try
  117. {
  118. using (OracleCommand cmd = new OracleCommand("SELECT 1 FROM DUAL", (OracleConnection)db))
  119. {
  120. read = cmd.ExecuteReader();
  121. }
  122. return true;
  123. }
  124. catch (Exception ex)
  125. {
  126. Console.WriteLine(ex.Message);
  127. }
  128. finally
  129. {
  130. if (read != null) read.Dispose();
  131. }
  132. return false;
  133. }
  134. public int GetSID(ref IDbConnection db)
  135. {
  136. //OracleDataReader read = null;
  137. //try
  138. //{
  139. // int sid = -1;
  140. // using (OracleCommand cmd = new OracleCommand("SELECT SID FROM SYS.V_$MYSTAT@XGCXMES WHERE ROWNUM =1", (OracleConnection)db))
  141. // {
  142. // read = cmd.ExecuteReader();
  143. // while (read.Read())
  144. // {
  145. // sid = Convert.ToInt32(read.GetValue(0));
  146. // read.Close();
  147. // return sid;
  148. // }
  149. // }
  150. //}
  151. //catch (Exception ex)
  152. //{
  153. // cwl.WriteLog(ex.Message, LogInfoLevel.Error, "GetSID", "ODP");
  154. //}
  155. //finally
  156. //{
  157. // if (read != null) read.Dispose();
  158. //}
  159. return -1;
  160. }
  161. }
  162. }