OdbcTest.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // OdbcTest.cs - Test for the ODBC ADO.NET Provider in System.Data.Odbc
  3. //
  4. // The test works on Windows XP using Microsoft .NET Framework 1.1 Beta
  5. //
  6. // To compile under Windows using Microsoft .NET 1.1
  7. // E:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\csc OdbcTest.cs /reference:System.Data.dll
  8. //
  9. // To compile under Windows using Mono:
  10. // mcs OdbcTest.cs -r System.Data.dll
  11. //
  12. // I have not tested it on Linux using unixODBC
  13. //
  14. // Author:
  15. // Daniel Morgan <[email protected]>
  16. //
  17. //
  18. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  19. //
  20. // Permission is hereby granted, free of charge, to any person obtaining
  21. // a copy of this software and associated documentation files (the
  22. // "Software"), to deal in the Software without restriction, including
  23. // without limitation the rights to use, copy, modify, merge, publish,
  24. // distribute, sublicense, and/or sell copies of the Software, and to
  25. // permit persons to whom the Software is furnished to do so, subject to
  26. // the following conditions:
  27. //
  28. // The above copyright notice and this permission notice shall be
  29. // included in all copies or substantial portions of the Software.
  30. //
  31. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  32. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  33. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  34. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  35. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  36. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  37. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  38. //
  39. using System;
  40. using System.Data;
  41. using System.Data.Odbc;
  42. namespace Test.OdbcTest
  43. {
  44. class OdbcTest
  45. {
  46. [STAThread]
  47. static void Main(string[] args)
  48. {
  49. OdbcConnection dbcon = new OdbcConnection();
  50. // connection string to a Microsoft SQL Server 2000 database
  51. // that does not use a DSN
  52. //dbcon.ConnectionString =
  53. // "DRIVER={SQL Server};" +
  54. // "SERVER=(local);" +
  55. // "Trusted_connection=true;" +
  56. // "DATABASE=pubs;";
  57. // connection string that uses a DSN.
  58. dbcon.ConnectionString =
  59. "DSN=LocalServer;UID=sa;PWD=";
  60. dbcon.Open();
  61. OdbcCommand dbcmd = new OdbcCommand();
  62. dbcmd.Connection = dbcon;
  63. dbcmd.CommandType = CommandType.Text;
  64. dbcmd.CommandText = "SELECT lname FROM employee";
  65. OdbcDataReader reader;
  66. reader = (OdbcDataReader) dbcmd.ExecuteReader();
  67. while(reader.Read()) {
  68. Console.WriteLine("Last Name: " + reader[0].ToString());
  69. }
  70. reader.Close();
  71. dbcmd.Dispose();
  72. dbcon.Close();
  73. }
  74. }
  75. }