I'm not exactly sure how this works in conjunction with user authorities to various libraries, but perhaps it will give you a place to start from. I use this to check if a library-file exists when connecting to an as400 system...our as400 is at V5R4, I'm not sure if it makes a difference as to what the error message would say. There is probably a better way, but this is what I've got and it seems to work for my purposes:
Private Function RunFileExists(ByVal instrLibAndFile As String, _
ByRef inconDb400 As IBM.Data.DB2.iSeries.iDB2Connection) As Boolean
'***********************************************************************
' This method will:
' Accept a command and run the ExecuteScalar Function checking
' for any errors
'***********************************************************************
Dim cmd As New IBM.Data.DB2.iSeries.iDB2Command
cmd.CommandText = "SELECT * FROM " & instrLibAndFile & " WHERE 1=2"
cmd.Connection = inconDb400
Dim boolFileExists As Boolean = False
If inconDb400.State <> ConnectionState.Open Then
inconDb400.Open()
End If
Try
Dim intI As Integer = cmd.ExecuteNonQuery
boolFileExists = True
Catch ex As IBM.Data.DB2.iSeries.iDB2SQLErrorException
'To determine if the file exists or not, we are at the mercy of
'what is in the exception message
'which currently will display the text "FILE not found" when a
'file is not found.
If ex.Message.ToUpper.Contains("FILE NOT FOUND") Then
'File does not exist
boolFileExists = False
Else
'Some other error occurred, throw exception
Throw New System.Exception(ex.ToString)
End If
Catch ex As Exception
'Some other error occurred, throw exception
Throw New System.Exception(ex.ToString)
Finally 'Always close connection
If inconDb400.State <> ConnectionState.Closed Then
inconDb400.Close()
End If
cmd.Dispose()
End Try
Return boolFileExists
End Function