Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP, ADO and AS400

Status
Not open for further replies.

LearningFox

Programmer
Nov 25, 2001
43
US
I am new to ASP, so please be gentle.

I am attempting to connect to a test file on our AS400. I have a sample ASP app from IBM as well as my own script. They both give me the same error message (see below). I did get the IBM sample to diplay data one time. It always leaves the file locked on the AS400.

error 'ASP 0115'
Unexpected error

/X3TierSamp/browse.asp

A trappable error occurred in an external object. The script cannot continue running.
 
Could you post the source. It's hard to find the reason only from the error description, since ASP is really poor with that.

Regards,
Durug
 
Below is the sample code from IBM. The first time I tried this, it worked. I think it has something to do with the connection to the AS400. Thanks.




<html>

<head>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html; charset=iso-8859-1&quot;>
<meta name=&quot;GENERATOR&quot; content=&quot;Microsoft FrontPage 4.0&quot;>
<title></title>
</head>

<body>

<h1 align=&quot;center&quot;>Client Access Express IIS Toolkit Sample<br>Main Menu</h1>

<h4 align=&quot;center&quot;>Version 1.2</h4>

<hr>

<p>This page was added in the updated version of the sample.&nbsp; You can override the default system name, userid, and password by using the following form. The new settings will apply <b> only </b> to your session. The default values can be changed by editing the global.asa file of the application.&nbsp;
See the <a href=&quot;readme%20IIS4.htm&quot;>readme IIS4.htm</a> or <a href=&quot;readme%20IIS5.htm&quot;>readme
IIS5.htm</a> files
for detailed information on how to setup the sample.
</p>


<!---- Need to process form and set globabl.asa ------>
<%
Dim S
Dim SesVals
SesVals = &quot;Session ID: &quot; & Session.SessionID & &quot;<br>&quot;
SesVals = SesVals & &quot;System: &quot; & Trim(Session(&quot;AS400_SystemName&quot;)) & &quot;<br>&quot;
SesVals = SesVals & &quot;User profile: &quot; & Trim(Session(&quot;AS400_Userid&quot;)) & &quot;<br>&quot;
SesVals = SesVals & &quot;Password: xxxxxx&quot; & &quot;<br>&quot; '& Trim(Session(&quot;AS400_Password&quot;)) & &quot;<br>&quot;
SesVals = SesVals & &quot;Library: &quot; & Trim(Session(&quot;Library&quot;)) & &quot;<br>&quot;
SesVals = SesVals & &quot;file: &quot; & Trim(Session(&quot;FileName&quot;)) & &quot;<br>&quot;
SesVals = SesVals & &quot;ODBC DSN:&quot; & Trim(Session(&quot;ODBC_DataSourceName&quot;)) & &quot;<br>&quot;

If Not isEmpty(Request.Form(&quot;txtAS400System&quot;)) then
If Len(Request.Form(&quot;txtUserID&quot;)) > 0 AND _
Len(Request.Form(&quot;txtPassword&quot;)) > 0 AND _
Len(Request.Form(&quot;txtAS400System&quot;)) > 0 then

'These are required
Session(&quot;AS400_Userid&quot;) = Request.Form(&quot;txtUserID&quot;)
Session(&quot;AS400_Password&quot;) = Request.Form(&quot;txtPassword&quot;)
Session(&quot;AS400_SystemName&quot;) = Request.Form(&quot;txtAS400System&quot;)

'These are optional
If Len(Trim(Request.Form(&quot;txtLibrary&quot;))) > 0 then Session(&quot;Library&quot;) = Request.Form(&quot;txtLibrary&quot;)
If Len(Trim(Request.Form(&quot;txtFileName&quot;))) > 0 then Session(&quot;FileName&quot;) = Request.Form(&quot;txtFileName&quot;)
If Len(Trim(Request.Form(&quot;txtDSN&quot;))) > 0 then Session(&quot;ODBC_DataSourceName&quot;) = Request.Form(&quot;txtDSN&quot;)

SesVals = &quot;Session ID: &quot; & Session.SessionID & &quot;<br>&quot;
SesVals = SesVals & &quot;System: &quot; & Trim(Session(&quot;AS400_SystemName&quot;)) & &quot;<br>&quot;
SesVals = SesVals & &quot;User profile: &quot; & Trim(Session(&quot;AS400_Userid&quot;)) & &quot;<br>&quot;
SesVals = SesVals & &quot;Password: xxxxxx&quot; & &quot;<br>&quot; '& Trim(Session(&quot;AS400_Password&quot;)) & &quot;<br>&quot;
SesVals = SesVals & &quot;Library: &quot; & Trim(Session(&quot;Library&quot;)) & &quot;<br>&quot;
SesVals = SesVals & &quot;file: &quot; & Trim(Session(&quot;FileName&quot;)) & &quot;<br>&quot;
SesVals = SesVals & &quot;ODBC DSN:&quot; & Trim(Session(&quot;ODBC_DataSourceName&quot;)) & &quot;<br>&quot;

response.write &quot;Session Info updated. <br>&quot; & SesVals
response.write &quot;The session will timeout after &quot; & Session.timeout & &quot; minutes of inactivity.<br>&quot;
Else
response.write &quot;<b> Incomplete information entered. </b> The session information was not updated.<br>&quot;
response.write SesVals
end if
Else
response.write &quot;New Session. &quot;
response.write &quot; Default Connect string is being used: <br>&quot; & SesVals
end if
%>
<form action=&quot;default.asp&quot; METHOD=POST>
<center>
<table border=&quot;0&quot;>
<tr>
<td>System Name</td>
<td><input type=&quot;text&quot; size=&quot;10&quot; name=&quot;txtAS400System&quot; value = &quot;<% Response.Write Request.Form(&quot;txtAS400System&quot;) %>&quot;></td>
</tr>

<tr>
<td>User ID</td>
<td><input type=&quot;text&quot; size=&quot;10&quot; name=&quot;txtUserId&quot; value = &quot;<% Response.Write Request.Form(&quot;txtUserId&quot;) %>&quot;></td>
</tr>
<tr>
<td>Password</td>
<td><input type=&quot;password&quot; size=&quot;10&quot; name=&quot;txtPassword&quot; value = &quot;<% Response.Write Request.Form(&quot;txtPassword&quot;) %>&quot;></td>
</tr>
<tr>
<td>Library</td>
<td><input type=&quot;text&quot; size=&quot;10&quot; name=&quot;txtLibrary&quot; value = &quot;<% Response.Write Request.Form(&quot;txtLibrary&quot;) %>&quot;></td>
</tr>
<tr>
<td>File Name</td>
<td><input type=&quot;text&quot; size=&quot;10&quot; name=&quot;txtFileName&quot; value = &quot;<% Response.Write Request.Form(&quot;txtFileName&quot;) %>&quot;></td>
</tr>

<tr>
<td>ODBC System Data Source Name</td>
<td><input type=&quot;text&quot; size=&quot;10&quot; name=&quot;txtDSN&quot; value = &quot;<% Response.Write Request.Form(&quot;txtDSN&quot;) %>&quot;></td>
</tr>

<tr>
<td align=&quot;center&quot; width=&quot;50%&quot;><input type = &quot;SUBMIT&quot; value=&quot;SUBMIT&quot;> </td>
<td align=&quot;center&quot;><input type=&quot;button&quot; value=&quot;End Session&quot; name=&quot;EndSess&quot; onClick=&quot;EndSess_OnClick();&quot;></td>
</tr>

</table>
</center>
</form>
<SCRIPT LANGUAGE=&quot;JScript&quot;>
function EndSess_OnClick()
{
window.location.href = &quot;EndSession.asp&quot;;
}
</SCRIPT>

<hr>

<h3> asp Samples</h3>
<a href=&quot;Versions.asp&quot;> Report Versions</a> - Verifies that the proper
Components are installed (Client Access and ADO).&nbsp; Verifies Client Access
Service Pack Level.&nbsp; Verifies the ODBC Datasource.<br>
<a href=&quot;Browse.htm&quot;> Browse tables</a> - Query a table using ODBC, OLEDB SQL,
or OLEDB RLA.<br>

<a href=&quot;rmtcmd.asp&quot;>Remote Command automation object</a><br>
<a href=&quot;DSNOption.asp&quot;>Set ODBC datasource options</a> such as the R450 option to prevent prompting.<br>

</body>
</html>



 
Unless I'm missing something, there is no connection made to the AS400 in that script...

The only things I see references are the request and session objects, which will not be connecting to the AS400.

A typical connection would look like:

dim constr, con
constr = &quot;connectionStringGoesHere&quot;
set con = server.createObject(&quot;ADODB.Connection&quot;)
con.open constr

Once you find some code that resembles that to some extent, you need to make sure that the connection is being closed and set = nothing, such as:

con.close
set con = nothing

not doing this explicitly can leave things in strange states where the scripts might have problems again.

hope that helps :)
paul
penny1.gif
penny1.gif
 
I just re-read my post and realized that it did not contain the connection code. That is in a seperate asp page. That is below.

<%

' This sample will dynamically generate a table for the QCUSTCDT file on the AS/400 and
' display all the records of the file. The method of retrieving the records is based on the
' user selection in browse.htm. For those records in which the CDTDUE field is
' greater than 0, the CDTDUE value is highlighted in red. If you removed the CDTDUE checking
' code you could use this ASP to generate a table for any AS/400 DB file.
'
' Global.ASA file contains the following information:
' - Library
' - File Name
' - Userid
' - Password
' - AS/400 System Name
' - ODBC data source name




'Always DIM your variables, even though you don't have to.
'All ASP variables are variants, you cannot specify the data type

Dim AS400Connection
Dim AS400Command
Dim AS400File_rs
Dim ConnectionString
Dim Color
Dim ColorEnd
Dim CommandText
Dim CommandType

On Error Resume Next
'dxd
Dim SesVals
SesVals = &quot;Session ID: &quot; & Session.SessionID & &quot;<br>&quot;
SesVals = SesVals & &quot;System: &quot; & Trim(Session(&quot;AS400_SystemName&quot;)) & &quot;<br>&quot;
SesVals = SesVals & &quot;User profile: &quot; & Trim(Session(&quot;AS400_Userid&quot;)) & &quot;<br>&quot;
SesVals = SesVals & &quot;Password: xxxxxx&quot; & &quot;<br>&quot; '& Trim(Session(&quot;AS400_Password&quot;)) & &quot;<br>&quot;
SesVals = SesVals & &quot;Library: &quot; & Trim(Session(&quot;Library&quot;)) & &quot;<br>&quot;
SesVals = SesVals & &quot;file: &quot; & Trim(Session(&quot;FileName&quot;)) & &quot;<br>&quot;
SesVals = SesVals & &quot;ODBC DSN:&quot; & Trim(Session(&quot;ODBC_DataSourceName&quot;)) & &quot;<br>&quot;
response.write SesVals



'Setup appropriate connection string and command information
Select Case Request.Form(&quot;ConnectionType&quot;)
Case &quot;IBMSQL&quot;
ConnectionString = &quot;Provider=IBMDA400;Data Source=&quot; & Session(&quot;AS400_SystemName&quot;) & &quot;;&quot;
CommandText = &quot;SELECT * FROM &quot; & Session(&quot;Library&quot;) & &quot;.&quot; & Session(&quot;FileName&quot;)
CommandType = adCmdText

Case &quot;IBMRLA&quot;
ConnectionString = &quot;Provider=IBMDA400;Data Source=&quot; & Session(&quot;AS400_SystemName&quot;) & &quot;;&quot;
CommandText = &quot;/QSYS.LIB/&quot; & Session(&quot;Library&quot;) & &quot;.LIB/&quot; & Session(&quot;FileName&quot;) & &quot;.FILE()&quot;
CommandType = adCmdTable

Case &quot;ODBC&quot;
ConnectionString = &quot;Provider=MSDASQL;DSN=&quot; & Session(&quot;ODBC_DataSourceName&quot;) & &quot;;&quot;
CommandText = &quot;SELECT * FROM &quot; & Session(&quot;Library&quot;) & &quot;.&quot; & Session(&quot;FileName&quot;)
CommandType = adCmdText
response.write connectionstring 'dxd
Case Else
'No connection type was selected, so redisplay the selection page
Response.Redirect(&quot;browse.htm&quot;)

End Select

'Open the connection
Set AS400Connection = Server.CreateObject(&quot;ADODB.Connection&quot;)
AS400Connection.Open ConnectionString,Session(&quot;As400_Userid&quot;),Session(&quot;AS400_Password&quot;)

Set AS400Command = Server.CreateObject(&quot;ADODB.Command&quot;)
AS400Command.ActiveConnection = AS400Connection

'Specify Read-Only. See the OLE/DB documentation in the Client Access/400 toolkit for more
'info on the Updatability property. This is a custom property only for the IBMDA400 property.
If (InStr(1,Request.Form(&quot;ConnectionType&quot;),&quot;IBM&quot;,vbTextCompare) > 0) Then
AS400Command.Properties(&quot;Updatability&quot;) = 0
End If

'Set the command to execute
AS400Command.CommandText = CommandText
AS400Command.CommandType = CommandType

'Execute the command on the AS/400
Set AS400File_rs = AS400Command.Execute

If (Err.Number = 0 ) Then

Response.Write(&quot;<table border=1 cellpadding=1 cellspacing=0>&quot;)
Response.Write(&quot;<tr bgcolor=#c8d8f8>&quot;)

' Loop through all the fields in the file and generate the column headings of the table
For Each fd in AS400File_rs.Fields
Response.Write(&quot;<td nowrap>&quot; & fd.Name & &quot;</td>&quot;)
Next

Response.Write(&quot;</tr>&quot;)

' Loop through all the records
While NOT AS400File_rs.EOF
Response.Write(&quot;<tr>&quot;)

'Loop through each field and generate the row the row in the table, if it's the
'CDTDUE field, check to see if it's greater than 0, if so, make it red
For Each field in AS400File_rs.Fields
Color = &quot;&quot;
ColorEnd = &quot;&quot;
If (field.Name = &quot;CDTDUE&quot;) Then
If (CDBL(field.Value) > 0) Then
Color = &quot;<font color=#ff0020>&quot;
ColorEnd = &quot;</font>&quot;
End IF
End If
Response.Write(&quot;<td nowrap>&quot; & color & field.Value & ColorEnd & &quot;</td>&quot;)
Next
Response.Write(&quot;</tr>&quot;)
AS400File_rs.MoveNext
Wend

Response.Write(&quot;</table>&quot;)

Else
'An Error Occurred
DisplayError AS400Connection, Err.Number, Err.Description, Err.Source, &quot;Main&quot;
End If

AS400File_rs.Close
Set AS400File_rs = Nothing
AS400Connection.Close
Set AS400Conection = Nothing
Set AS400Command = Nothing

'**************************************************************************************
'***
'*** Subroutine DisplayError
'***
'**************************************************************************************
Sub DisplayError(Connection,errNum,errDesc,errSource,proc)

On Error Resume Next

Response.Write(&quot;<br>VB Error Number: <b>&quot; & errNum & &quot; [0x&quot; & Hex(errNum) & &quot;]</b>&quot;)
Response.Write(&quot;<br>Err.Description: <b>&quot; & errDesc & &quot;</b>&quot;)
Response.Write(&quot;<br>Err.Source: <b>&quot; & errSource & &quot;</b>&quot;)
Response.Write(&quot;<br>Procedure: <b>&quot; & proc & &quot;</b>&quot;)

Response.Write(&quot;<br>Connection errors: <b>&quot; & Connection.Errors.Count & &quot;</b>&quot;)
If (Connection.Errors.Count > 0) Then
For Each ErrorMsg in Connection.Errors
Response.Write(&quot;<br>&quot; & ErrorMsg.Description)
Next
End If

End Sub

%>
 
Just at a cursory glance, it looks like pretty solid code to me... notice the closing and setting of the objects to nothing. That should release the resources and return the target objects to a ready state.

But with no experience connecting to an AS400, I'm just not sure of the pitfalls that might occur.

I don't suppose the developers of this code are willing to talk to you about what might have gone wrong?

Short of that, here's a kb article that talks about this error. The news is not good, though. It's not terribly descriptive:


^^you'll have to copy and paste the entire link because of MS's use of semi-colons in their links. That one still baffles me as to why they would do that.

There are many more 0115 error articles out there. Head over to and pick Active Server Pages from the product list, and enter &quot;ASP 0115&quot; in the search box, and go.

Wish I could help more. :-(
paul
penny1.gif
penny1.gif
 
Thanks, Paul. We do have support from IBM but I have found that forums like this are usually quicker and more responsive, not to mention more informative.
 
Thanks for the help. I got it working today. I downloaded a service pack for Client Access and off it went!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top