需要使用Winform Application检查AS400服务器上的文件是否存在 [英] Need to Check file exists on AS400 server using Winform Application

查看:113
本文介绍了需要使用Winform Application检查AS400服务器上的文件是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用Windows应用程序,需要使用用户凭据检查特定库中是否存在文件.
请提出建议.

注意:.Net framework 1.1(VS2003)

Hi,
I am working on a Windows Application where i need to check a file exists in particular library with user crediantials.
Please suggest how to do it.

Note : .Net framework 1.1 (VS2003)

推荐答案

我不确定如何与各种库的用户权限结合使用,但也许会您是一个起点.我用它来检查连接到as400系统时是否存在库文件...我们的as400在V5R4上,我不确定它是否对错误消息说的有所不同.可能有更好的方法,但这是我所拥有的,并且似乎可以满足我的目的:

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


这篇关于需要使用Winform Application检查AS400服务器上的文件是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆