在花几天后研究并试图弄清楚独奏,我真的可以使用一些帮助。

我正在尝试直接从.NET查询AS400的数据库,而无需使用AS400程序文件。除了从AS400管理员开始“继续并尝试”以外的支持非常小(我被告知我以前尚未完成)。

我真的很想使用cwbx。下面的代码成功连接,但我可以真正在正确的方向上使用指针如何构建查询:

Dim As400 As New AS400System
Dim AsProgram As New cwbx.Program
Dim AsCommand As New cwbx.Command
Dim strQuery As String

As400.Define("AS400")
As400.UserID = ""
As400.Password = ""
As400.IPAddress = ""
As400.Connect(cwbcoServiceEnum.cwbcoServiceRemoteCmd)

If As400.IsConnected(cwbcoServiceEnum.cwbcoServiceRemoteCmd) = 1 Then
    MsgBox("Valid Connection")
Else
    MsgBox("Invalid Connection")
    Exit Sub
End If

'-----------------------------------------------------------------------------------------
'Trying to figure out first if this syntax is correct, and if so... where/how to call it??
'-----------------------------------------------------------------------------------------
strQuery = "SELECT * FROM Library.File WHERE FILEFIELD='Criteria'"
' ---

AsProgram.LibraryName = ""
AsProgram.ProgramName = "" '?
AsProgram.system = As400

'Assuming this will end up being a program call?
'AsProgram.Call()

As400.Disconnect(cwbcoServiceEnum.cwbcoServiceRemoteCmd)
.

我对任何其他方法/建议都很开放。我查找了来自IBM的网站以及MSDN的指南,并且在不使用AS400程序文件的情况下,实际上都没有直接查询。这是可能的吗?

有帮助吗?

解决方案

这是一个简单的控制台应用程序,它将从一个表中检索所有记录并显示行计数。

Imports System.Data.OleDb

Module Module1

  Sub Main()
    Dim cmd As New OleDbCommand
    Dim table As String = "YOUR TABLE"
    cmd.CommandText = "SELECT * FROM " & table
    Dim ip As String = "YOUR AS/400 IP GOES HERE"
    Dim user As String = "YOUR USER ID"
    Dim pass As String = "YOUR PASSWORD"
    Dim defaultLib As String = "YOUR LIBRARY"
    Dim connstring As String = "Provider=IBMDA400;" & _
                               "Data Source=" & ip & ";" & _
                               "Force Translate=0;" & _
                               "Default Collection=" & defaultLib & ";" & _
                               "User ID=" & user & ";" & _
                               "Password=" & pass
    cmd.Connection = New OleDbConnection(connstring)
    cmd.Connection.Open()
    Dim dr As OleDbDataReader = cmd.ExecuteReader
    Dim dt As New DataTable
    dt.Load(dr)

    Console.WriteLine(dt.Rows.Count)
    Console.WriteLine("Press ENTER to close...")
    Console.ReadLine()
  End Sub

End Module
.

其他提示

remotecmd服务基本上是一个rexcd守护程序。当您想要简单查询DB表时,不确定为什么搞乱这一点。 IBM I中的集成DB可通过ODBC,OLEDB,JBDC访问,最重要的是为您提供ADO.NET提供商。

http://www-03。 IBM.com/systems/power/software/i/access/windows/dotnet.html

所有上述驱动程序都可以在IBM i访问软件中提供。请注意,虽然某些IBM I访问功能是可收费的,但EX 5250仿真,您必须购买许可证;数据访问提供程序不是。

包含在IBM I Access Package是一个名录的集合,称为“程序员Toolkit”

使用.NET数据提供程序从该工具包中的示例:

  Public Sub Example()
    Dim cn As iDB2Connection = New iDB2Connection("DataSource=mySystemi;")
      Dim da As New iDB2DataAdapter("select * from mylib.mytable", cn)
  End Sub
.

最后注意(免费).NET提供程序不支持Microsoft的实体框架(EF)。如果您需要EF支持,您必须支付DB2 Connect

http://www-03.ibm.com/软件/产品/ en / db2-connect-family

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top