Need to check file exsits on AS400 server using Winform Application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • veerusrahul
    New Member
    • Sep 2009
    • 9

    Need to check file exsits on AS400 server using Winform Application

    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)
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    System.IO.File. Exists(string PathToFile);

    Comment

    • veerusrahul
      New Member
      • Sep 2009
      • 9

      #3
      But it is in remote server , and it is a AS400 server ,We might need to provide user id and password

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Oh wow, with a bit of searching, it looks like you can do this with ODBC!!

        Obviously I haven't tried this myself because I don't have an AS400 of my own...I took the following code from a google search:
        Code:
        'Define the ODBC Connection string
         Dim MyODBCConnection As New OdbcConnection("Driver={Client Access ODBC Driver (32-bit)};" & _
                "System=AS400Name;" & _
                "TRANSLATE=1;" & _
                "Uid=UserID;" & _
                "Pwd=User Password")
        'Open the connection
                MyODBCConnection.Open()
        
        'Define the SQL statement to extract the data from the AS400
        Dim selectCMD As OdbcCommand = New OdbcCommand("SELECT * FROM LIBRARY.FILE WHERE FILEFIELD='YourChoice' order by FILEFIELD", MyODBCConnection)
        
        'Initialize the reader
        Dim dr As OdbcDataReader = selectCMD.ExecuteReader
        
        Try
        'Set the mouse to show a Wait cursor
                    Me.Cursor = Cursors.WaitCursor
        'start the Read loop
                    While dr.Read
        'Note: the numbers in double quotes represent the column number from the AS400 database
        'Add the data to the list view
                        Dim listItem As New ListViewItem(dr.GetString("2"))
                        listItem.SubItems.Add(dr.GetString("3"))
                        ListView1.Items.Add(listItem)
        'End the loop
                    End While
        'Reset the cursor
                    Me.Cursor = Cursors.Default
        
                Catch ex As Exception
                End Try
        
        'Close the connection
         MyODBCConnection.Close()
         MyODBCConnection.Dispose()
        -Frinny

        Comment

        • veerusrahul
          New Member
          • Sep 2009
          • 9

          #5
          Hi Frinavale,
          The AS400 server is iSeriesDB2. i added IBM.DB2.ISeries .dll to reference and added and tried following code , but getting exception in first line . please let me know if i need to install any drivers or any other dll.
          Code:
          Dim cn As iDB2Connection = New iDB2Connection
          Dim cmd As iDB2Command = cn.CreateCommand()
          Dim dataFromTable As String
          cmd.CommandText = "select * from file1"
          cn.ConnectionString = "DataSource=xyz; Naming=System; LibraryList="
          dataFromTable = CType(cmd.ExecuteScalar(), String)
          cn.Open()
          cn.Close()
          Exception:
          An unhandled exception of type 'IBM.Data.DB2.i Series.iDB2DCFu nctionErrorExce ption' occurred in ibm.data.db2.is eries.dll

          Additional information: Exception calling CwbDc.GetConsta nts from iDB2Constants constructor.
          Last edited by Frinavale; Dec 9 '09, 10:22 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

          Comment

          Working...