I'm Struggling returning a result set from an AS400 database using a C# console app... I can connect to the database and i have verified the connection through the AS400 logs however I seem to run into the following error:
System.InvalidCastException was unhandled Message=The data type returned is currently not supported by the provider. Source=IBM.Data.DB2.iSeries StackTrace: at IBM.Data.DB2.iSeries.iDB2DbTypeUtility.MapSQLTypeToDCPCType(DcSqlTypes sqlType, Int32 colccsid, UInt32 length) at IBM.Data.DB2.iSeries.iDB2Command.setRowOfParameterData(MpDcData[]& dcDataRow) at IBM.Data.DB2.iSeries.iDB2Command.execute() at IBM.Data.DB2.iSeries.iDB2Command.ExecuteNonQuery() at GeacFutureDelivery.Program.Main(String[] args) in C:\Users\harlim\documents\visual studio 2010\Projects\GeacFutureDelivery\GeacFutureDelivery\Program.cs:line 40 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:
My source is:
var connectionString = "<Connection String>";
int startDate = 1120530;
int endDate = 1120602;
try
{
using (var connection = new iDB2Connection(connectionString))
{
connection.Open();
iDB2Transaction trans = connection.BeginTransaction();
iDB2Command command = connection.CreateCommand();
string query = "DRLOBJ01.GETORDPCD";
command.Transaction = trans;
command.CommandType = CommandType.StoredProcedure;
command.CommandText = query;
command.CommandTimeout = 0;
command.Parameters.Add("DTSTR", iDB2DbType.iDB2Integer).Value = startDate;
command.Parameters.Add("DTEND", iDB2DbType.iDB2Integer).Value = endDate;
command.Prepare();
using (iDB2DataReader reader = command.ExecuteReader())
{
int iCUSO51 = reader.GetOrdinal("CUSO51");
int iORDN51 = reader.GetOrdinal("ORDN51");
int iDTDR51 = reader.GetOrdinal("DTDR51");
int iOPST45 = reader.GetOrdinal("OPST45");
while (reader.Read())
{
if (!string.IsNullOrEmpty(reader.GetString(iCUSO51)))
{
Console.WriteLine((string)reader[iCUSO51]);
Console.WriteLine((string)reader[iORDN51]);
Console.WriteLine((string)reader[iDTDR51]);
Console.WriteLine((string)reader[iOPST45]);
}
}
}
}
}
catch (iDB2CommErrorException ex)
{
Console.WriteLine(ex.Message);
}
}
Any thoughts?