OleDbCommand_Dispose.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // Copyright (c) 2006 Mainsoft Co.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. using System;
  24. using System.Data;
  25. using System.Data.OleDb;
  26. using MonoTests.System.Data.Utils;
  27. using NUnit.Framework;
  28. namespace MonoTests.System.Data.OleDb
  29. {
  30. [TestFixture]
  31. public class OleDbCommand_Dispose : GHTBase
  32. {
  33. public static void Main()
  34. {
  35. OleDbCommand_Dispose tc = new OleDbCommand_Dispose();
  36. Exception exp = null;
  37. try
  38. {
  39. tc.BeginTest("OleDBCommand_Dispose");
  40. tc.run();
  41. }
  42. catch(Exception ex)
  43. {
  44. exp = ex;
  45. }
  46. finally
  47. {
  48. tc.EndTest(exp);
  49. }
  50. }
  51. //problems from Synergy
  52. //Ofer,
  53. //Take a look at #1. Test this to see if we have a problem in dispose. If we do, add a test for this to make sure we catch it in next rounds.
  54. //
  55. //-----Original Message-----
  56. //From: David Teplitchi [mailto:[email protected]]
  57. //Sent: Sunday, March 21, 2004 9:31 AM
  58. //To: //Oved Yavine//
  59. //Subject: 2 problems from Synergy
  60. //Please check those 2 problems reported by Synergy and tell me what do you think.
  61. //1) The following code works in dotnet but doesn//t work in j2ee.
  62. //// Oracle Drivers
  63. //OleDbConnection Connect;
  64. //OleDbDataReader DbReader;
  65. //OleDbCommand DbCommand;
  66. //IDataReader DR;
  67. //string sSQL;
  68. //int iField;
  69. //bool bFound;
  70. //try
  71. //{
  72. //Connect = new OleDbConnection("Provider=\"MSDAORA.1\";User
  73. //ID=COM;Password=SQL;Data Source=LLO1;HostName=WS10359;Port=1521");
  74. //Connect.Open();
  75. //sSQL = "SELECT * FROM PRODUCT WHERE PRO_SKU = //SKU_208//";
  76. //DbCommand = new OleDbCommand(sSQL, Connect);
  77. //DbReader = DbCommand.ExecuteReader(CommandBehavior.SingleRow);
  78. //DR = DbReader;
  79. //DbCommand.Dispose(); // comment out
  80. ////DbCommand = null;
  81. //bFound = DbReader.HasRows;
  82. //DR.Read();
  83. //// Get Column Ordinal
  84. //iField = DR.GetOrdinal("PRO_DESCRIPTION");
  85. //string sDesc = DR.GetString(iField);
  86. //}
  87. //catch(Exception e)
  88. //{
  89. //this.WriteErrorLog(e.Message);
  90. //}
  91. //i have identified the problem as being "DbCommand.Dispose()". If you comment this line out or make it
  92. //"DbCommand = null", then its okay. So this instruction doesnt work the same in both in .net and j2ee.
  93. [Test]
  94. public void run()
  95. {
  96. Exception exp = null;
  97. //OleDbConnection con = null;
  98. //this test was added due to a request from Oved:
  99. //this bug occur on all databases (SQL,Oracle,DB2)
  100. OleDbCommand DbCommand = null;
  101. OleDbConnection Connect = new OleDbConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
  102. Connect.Open();
  103. DbCommand = new OleDbCommand("SELECT * FROM Customers", Connect);
  104. OleDbDataReader DbReader = DbCommand.ExecuteReader();
  105. BeginCase("Check DataReader.IsClosed - before dispose");
  106. try
  107. {
  108. Compare(DbReader.IsClosed,false); //.Net=false, GH=false
  109. }
  110. catch (Exception ex){exp = ex;}
  111. finally{EndCase(exp);exp = null;}
  112. BeginCase("Check DataReader.IsClosed - after dispose");
  113. try
  114. {
  115. DbCommand.Dispose();
  116. Compare(DbReader.IsClosed,false); //.Net=false, GH=true
  117. }
  118. catch (Exception ex){exp = ex;}
  119. finally{EndCase(exp);exp = null;}
  120. }
  121. }
  122. }