Sunday, October 17, 2004

AS/400 iseries in ASP.NET

Issue
Connecting to AS/400 from ASP.NET, following are the options available:
1. rfrompcb.exe

Fails with no error message but the following output:

IBM iSeries Access for WindowsVersion 5 Release 2 Level 0Transfer data to iSeries(C) Copyright IBM Corporation and Others 1984, 2002. All rights reserved.U.S. Government Users Restricted Rights - Use, duplication or disclosurerestricted by GSA ADP Schedule Contract with IBM Corp.Licensed Materials - Property of IBM

2. Program Files/IBM/Client Access/Shared/cwbx.dll - IBM AS/400 Client Acess Express ActiveX Object Library

Fails with [COMException] 'Unspecified Error' exception

Conclusion

The conclusion after a detailed study was the connectivity failed from ASP.NET but worked with from commandline or desktop application.

Problem

The problem is the identity under which aspnet worker process works is as configured in machine.config meaning 'machine' or SYSTEM or any NT user as specified and this user doesn't have rights to access AS/400 through the firewall.

Solution

The solution to this problem is to set the username and password values of tag in machine.config to the user that had access to AS/400 and limited rights on the webserver.

<ProcessModel>

Many a times asp.net code fails with or without an error but if the same is tried manually, it works!

Example:
  • Open Browser and type a URL; you are able to visit the site but when you try to do the same in ASP.NET using webrequest.create method, it fails with an error The underlying connection was closed: Unable to connect to the remote server.
  • Run a batch file that utilizes network resources; the batch file executes successfully but when you try to do the same in ASP.NET using process.start method, it fails without any error
Wonder why?

The reason is ASP.NET by default runs under the context of ASPNET user, change the <processmodel> tag and specify a user who is authorized to access the web server as well as network/domain resources and your code will work.