Hi,

I have a problem with .Net platform fetching data from DB2 on AS400 using DB2Connect OLEDB Provider, and iSeries Access ODBC driver. This is about getting my program to recognize the Timestamp data type returned from a query correctly. Using OLEDB all Date, Time and Timestamp are C#ystem.String. But with ODBC, they are correct.

Now, my real application crashes the aspnet_wp when I use ODBC driver. I open up the Event Viewer it reported something about COM+. So I have to use OLEDB, but it reports data type wrong.

Is there anyone who had this problem before? Do I need sort of DB2 fix packs or anything?

I wrote a little program to demonstrate my problem as followed:

sql: create table test3 (f1 date, f2 time, f3 timestamp)

C#:

// use DB2Connect OLEDB Provider
public static void testOleDbReader()
{
string cmd = "select * from test3";
string strConn = "Provider=IBMDA400;Data Source=xxx.xxx.xxx.xxx;User id=xxx;Password=xxx";
OleDbConnection cn = new OleDbConnection(strConn);
OleDbDataAdapter da;
DataSet ds = new DataSet();
cn.ConnectionString=strConn;
try {
da = new OleDbDataAdapter();
da.SelectCommand = new OleDbCommand(cmd);
da.SelectCommand.Connection = cn;
cn.Open();
da.Fill(ds);
OleDbDataReader myReader = da.SelectCommand.ExecuteReader();
foreach (DataColumn c in ds.Tables[0].Columns) {
Console.WriteLine(c.DataType);
}
} catch (Exception e) {
System.Console.WriteLine(e);
} finally {
cn.Close();
cn.Dispose();
}
}

result:
System.String
System.String
System.String

// use iSeries ODBC Driver with system dsn name 'xxx'
public static void testOdbcReader()
{
string cmd = "select * from test3";
string strConn = "DSN=xxx;UID=xxx;PWD=xxx;DBQ=xxx";
OdbcConnection cn = new OdbcConnection(strConn);
OdbcDataAdapter da;
DataSet ds = new DataSet();
cn.ConnectionString=strConn;
try {
da = new OdbcDataAdapter();
da.SelectCommand = new OdbcCommand(cmd);
da.SelectCommand.Connection = cn;
cn.Open();
da.Fill(ds);
OdbcDataReader myReader = da.SelectCommand.ExecuteReader();
foreach (DataColumn c in ds.Tables[0].Columns) {
Console.WriteLine(c.DataType);
}
} catch (Exception e) {
System.Console.WriteLine(e);
} finally {
cn.Close();
cn.Dispose();
}
}

result:
System.DateTime
System.TimeSpan
System.DateTime