【问题标题】:Possible to query As400 DB2 via VB.Net without a PRG?可以在没有 PRG 的情况下通过 VB.Net 查询 As400 DB2 吗?
【发布时间】:2014-07-29 23:31:16
【问题描述】:

在花了几天的时间研究并试图单独解决这个问题后,我真的需要一些帮助。

我正在尝试直接从 .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 程序文件的情况下实际上都没有进行直接查询。这甚至可能吗?

【问题讨论】:

  • 有帮助的搜索关键字是 ODBC 和 OLE DB。

标签: vb.net ibm-midrange db2-400


【解决方案1】:

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

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

【讨论】:

  • 请注意,这是使用 OLEDB 驱动程序。 IBM i 有一个 .NET 数据提供程序。
【解决方案2】:

remotecmd 服务基本上是一个 Rexcd 守护进程。当您想简单地查询数据库表时,不确定为什么要搞砸。 IBM i 中的集成 DB 可通过 ODBC、OLEDB、JBDC 访问,最重要的是,您可以通过 ADO.NET 提供程序访问。

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

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

IBM i Access 包中包含一组文档,称为“程序员工具包”

使用该工具包中的 .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/software/products/en/db2-connect-family

【讨论】:

    猜你喜欢
    • 2019-12-02
    • 2021-05-29
    • 1970-01-01
    • 1970-01-01
    • 2017-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多