I have the following query to put some data from rows in columns:
string qry3 =
"SELECT TABLENAME1.SLONO AS ORDER, TABLENAME1.SLLNNO AS LINE " +
", MAX(CASE WHEN TABLENAME2.CZVRNM in ('SLEEVEDEPTH', 'LENGTH') THEN CAST(RTRIM(TABLENAME2.CZREFD) AS FLOAT(53)) END) AS SLEEVE " +
", MAX(CASE WHEN TABLENAME2.CZVRNM in ('INSTALLATION') THEN CAST(RTRIM(TABLENAME2.CZREFD) AS FLOAT(53)) END) AS DAMPER_AI " +
"FROM LOCATION.LOCATION2.TABLENAME1 TABLENAME1 LEFT JOIN LOCATION.LOCATION2.TABLENAME2 TABLENAME2 " +
" ON (TABLENAME1.SLONO = TABLENAME2.SPONO AND TABLENAME1.SLLNNO = TABLENAME2.SPLNNO) " +
"GROUP BY TABLENAME1.SLONO, TABLENAME1.SLLNNO ";
But when I try to run it in the following code:
try
{
conAS400.Open();
iDB2Command command = conAS400.CreateCommand();
command.CommandText = qry3;
command.CommandTimeout = 0;
iDB2DataReader reader = command.ExecuteReader();
dtAS400 = new DataTable();
dtAS400.Load(reader); //<-- The exception occurs here. I can't even catch it
conAS400.Close();
retrieved = true;
}
catch (Exception ex)
{
MessageBox.Show("Could not retrive the information. Exception: " + ex.Message);
retrieved = false;
}
finally
{
conAS400.Close();
}
I get this exception:
"IBM.Data.DB2.iSeries.iDB2DCFunctionErrorException: 'An unexpected exception occurred. Type: System.AccessViolationException, Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt..'"
I have other queries that work just fine, but this one does not. I even tried the query on SQL as follows (credit to Gordon Linoff for providing this code):
SELECT
A.IDA, A.SomeInfo,
MAX(CASE WHEN VarName in ('Depth', 'Depth2') THEN VarValue END) AS Depth,
MAX(CASE WHEN VarName in ('Length') THEN VarValue END) AS Length
FROM
A
LEFT JOIN
B ON A.IDA = B.IDA
GROUP BY
A.IDA, A.SomeInfo
And it works. What can I do?
Drivers:
Client Access ODBC Driver (32-bit) 12.00.00.00
iSeries Access ODBC Driver 12.00.00.00
EDIT: Here's the sql query without being a string.
SELECT TABLENAME1.SLONO AS ORDER, TABLENAME1.SLLNNO AS LINE,
MAX(CASE WHEN TABLENAME2.CZVRNM in ('SLEEVEDEPTH', 'LENGTH') THEN CAST(RTRIM(TABLENAME2.CZREFD) AS FLOAT(53)) END) AS SLEEVE,
MAX(CASE WHEN TABLENAME2.CZVRNM in ('INSTALLATION') THEN CAST(RTRIM(TABLENAME2.CZREFD) AS FLOAT(53)) END) AS DAMPER_AI
FROM LOCATION.LOCATION2.TABLENAME1 TABLENAME1 LEFT JOIN LOCATION.LOCATION2.TABLENAME2 TABLENAME2
ON (TABLENAME1.SLONO = TABLENAME2.SPONO AND TABLENAME1.SLLNNO = TABLENAME2.SPLNNO)
GROUP BY TABLENAME1.SLONO, TABLENAME1.SLLNNO