Ashwin Behera
Ashwin Behera

Reputation: 47

Error while reading specific O-type DBCS data column from AS400 db2 using C# datareader

I am trying to fetch some records from IBM AS400 db2 database.

here i am selecting records from AS400 using select query where there are multiple columns having different data type. now problem arises here when i try to read specific 2 columns where the data type is 'O' - DBCS which contains the simple Name and short name of persons.

                   foreach (var record in source.Read(recordsObject, i))
                        {
                            for (int j = 0; j < n; j++)
                            {
                                // mycode to show record
                            }
                        }

Its a simple select query without any join, nothing.

select col1,col2, col3, col4, col5 from as400Table

I have tried with casting it at query itself as varchar with different sizes, tries various ways, but it shows me the error like this --

"The data value could not be converted for reasons other than sign mismatch or data overflow. For example, the data was corrupted in the data store but the row was still retrievable."

I have also tried changing the driver to IBM i Access for windows 7.1 but there also it gives me error like -- Conversion Error with message code - 6101.

other then this 2 columns, remaining columns are easily retrievable.

is there any specific issue while reading this type of data using C# ?

here i am using IBM iAccess Client Solution to connect with AS400.

Please suggest any solutions for this, i have searched at internet and it

Any suggestions is appreciated. Thanks.

Edit:

I am retrieving the data like this as the alternate to above mentioned code.

using (iDB2Connection connection1 = new iDB2Connection(connectionString))
{
 connection1.Open();

string sql = @"select col1,col2, col3, col4, col5 from as400Table";
    using (iDB2Command command = new iDB2Command(sql, connection1))
                    {
                        using (iDB2DataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {

                            }
                        }
                        }
 connection1.close();
}

Upvotes: 0

Views: 150

Answers (1)

David G
David G

Reputation: 4014

It's been a long time since I worked on DBCS tables, but I think you may have to set your connection to use a specific CCSID so the database can trans-code between the client app and the table.

I don't know C#, so I really can't tell you how this would be done.

Upvotes: 0

Related Questions