2 /// DB2DriverCS Test Code - A DB2 driver test for .Net
3 /// Copyright 2003 By Christopher Bockner
4 /// Released under the terms of the MIT/X11 Licence
5 /// Please refer to the Licence.txt file that should be distributed with this package
6 /// This software requires that DB2 client software be installed correctly on the machine
7 /// (or instance) on which the driver is running.
16 namespace TestDB2Conn
{
18 /// Code to test DB2DriverCS.
22 static void DoTest(string database
, string userid
, string password
)
24 IDbCommand command
= null;
25 string connectionString
= String
.Format(
26 "DSN={0};UID={1};PWD={2}",
27 database
, userid
, password
);
29 Console
.WriteLine("Create DB2 client Connection...");
30 DB2ClientConnection DB2Conn
= new DB2ClientConnection();
32 Console
.WriteLine("connection string: " + connectionString
);
34 Console
.WriteLine("Set connection string...");
35 DB2Conn
.ConnectionString
= connectionString
;
37 Console
.WriteLine("Open a connection...");
40 string createTestTableSQL
=
41 "CREATE TABLE mono_db2_test1 ( " +
42 " testid varchar(2), " +
43 " testdesc varchar(16) " +
45 Console
.WriteLine("SQL:\n" + createTestTableSQL
);
47 Console
.WriteLine("Create a command using sql and connection...");
48 command
= new DB2ClientCommand(createTestTableSQL
,DB2Conn
);
49 Console
.WriteLine("Execute Non Query...");
50 command
.ExecuteNonQuery();
52 string selectSQL
= "select * from employee";
53 Console
.WriteLine("SQL:\n" + selectSQL
);
54 Console
.WriteLine("create command and set connection and connection string...");
55 command
= new DB2ClientCommand(selectSQL
,DB2Conn
);
56 Console
.WriteLine("ExecuteReader...");
57 IDataReader dr
= command
.ExecuteReader();
58 Console
.WriteLine("Read row...");
60 Console
.WriteLine("Read row...");
62 Console
.WriteLine("GetString...");
63 string dt
= dr
.GetString(1);
64 Console
.WriteLine("dt: " + dt
);
65 string s
= dr
.GetString(5);
66 Console
.WriteLine("s: " + s
);
67 DateTime t
= dr
.GetDateTime(6);
68 Console
.WriteLine("t: " + t
);
70 Console
.WriteLine("Close connection...");
73 catch(DB2ClientException e
) {
74 System
.Console
.Write(e
.Message
);
78 /// The main entry point for the application.
81 static void Main(string[] args
)
84 Console
.WriteLine("Usage: mono TestDB2Conn.exe database userid password");
86 Console
.WriteLine("Test Begin.");
87 // database, userid, password
88 DoTest(args
[0], args
[1], args
[2]);
89 Console
.WriteLine("Test End.");