Connect to AS400 using .NET

Viewed 59750

I am trying to build a .NET web application using SQL to query AS400 database. This is my first time encountering the AS400.

What do I have to install on my machine (or the AS400 server) in order to connect? (IBM iSeries Access for Windows ??)

What are the components of the connection string?

Where can I find sample codes on building the Data Access Layer using SQL commands?

Thanks.

7 Answers

Extremely old question - but this is still relevant. I needed to query our AS/400 using .NET but none of the answers above worked and so I ended up creating my own method using OleDb:

   public DataSet query_iseries(string datasource, string query, string[] parameterName, string[] parameterValue)
    {
        try
        {
            // Open a new stream connection to the iSeries
            using (var iseries_connection = new OleDbConnection(datasource))
            {
                // Create a new command
                OleDbCommand command = new OleDbCommand(query, iseries_connection);

                // Bind parameters to command query
                if (parameterName.Count() >= 1)
                {
                    for (int i = 0; i < parameterName.Count(); i++)
                    {
                        command.Parameters.AddWithValue("@" + parameterName[i], parameterValue[i]);
                    }
                }

                // Open the connection
                iseries_connection.Open();

                // Create a DataSet to hold the data
                DataSet iseries_data = new DataSet();

                // Create a data adapter to hold results of the executed command
                using (OleDbDataAdapter data_adapter = new OleDbDataAdapter(command))
                {
                    // Fill the data set with the results of the data adapter
                    data_adapter.Fill(iseries_data);

                }

                return iseries_data;
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
            return null;
        }
    }

And you would use it like so:

DataSet results = query_iseries("YOUR DATA SOURCE", "YOUR SQL QUERY", new string[] { "param_one", "param_two" }, new string[] { "param_one_value", "param_two_value"}); 

It returns a DataSet of the results returned. If anyone needs/wants a method for inserting/updating values within the IBM AS/400, leave a comment and I'll share...

Check out http://asna.com/us/ as they have some development tools working with SQL and the AS400.

Related