【问题标题】:Universe 9+ system, UniObjects (not for .NET) - How to convert examples from VB 6 to C#Universe 9+ 系统,UniObjects(不适用于 .NET)- 如何将示例从 VB 6 转换为 C#
【发布时间】:2016-12-01 15:05:49
【问题描述】:

我正在使用一个多值数据库,该数据库当前使用 IBM U2(现为 Rocket Software)的 UniObjects 软件连接到 Universe 9.+ 系统。这不是 Rocket Software 为 Universe 10+ 和 11+ 系统推出的 UniObjects for .NET。我必须用来尝试连接到 Universe 9+ 系统的唯一示例是使用 Visual Basic 6.0,我需要使用 C#。谁能告诉我如何在 C# 中连接到 Universe 9+ 系统?基本上,我正在尝试将我在 VB 6 中使用的内容转换为 C#,以便连接到该系统。感谢您提供的所有帮助。文档中的一些示例如下:

Sub SampleFile ()
' SampleFile
'
' This routine creates a new session and opens the chosen
account's VOC
' file. The user is asked for a record id from VOC (e.g.
RELLEVEL), which
' is read and displayed in a message box. Finally the session
is closed.
Dim objSession As object ' The Session to the database
Dim objFile As object ' The file to open (VOC)
Const UVE_NOERROR = 0 ' From UVOAIF.TXT - no error
' The registered name of a database Session - Version 1
Const UV_SESSION_OBJECT = "UniObjects.unioaifctrl"
'
' Create a Session object to work with
' - This is a contrived sample, in a full application the
session object
' - would typically be a Global variable that is set once
maybe in
' - response to a menu selection (e.g. Connect) on the main
form.
'
Set objSession = CreateObject(UV_SESSION_OBJECT)
If objSession Is Nothing Then
' NB. Errors will be reported by VB
Exit Sub ' End the program
End If
objSession.UserName = Input.Box ("User Name:","Login")
objSession.Password = Input.Box ("Password:","Password")
'
' Establish a connection to the database server. By default it
displays
' a dialog box to request the HostName and AccountPath property
values.
'
objSession.Connect
If objSession.IsActive Then
'
' Open the VOC file
'
Set objFile = objSession.OpenFile("VOC")
If objFile Is Nothing Then
MsgBox "Unable to open VOC file (" & objSession.Error &
")"
Exit Sub ' End the program
End If
'
' Read user entered record from the VOC e.g. RELLEVEL
'
objFile.RecordId = InputBox("Enter Record Id:", "Record Id")
objFile.Read
File Object: Example 3-85
/productinfo/alldoc/UNIVERSE10/uv
objs/Ch3
If objFile.Error = UVE_NOERROR Then
' Display the record in a message box and close file
MsgBox objFile.Record
objFile.CloseFile ' Close the file - Good practice
Else
MsgBox "Unable to read (" & objFile.RecordId & ") record
from
å VOC " & objFile.Error
End If
'
' Close the session
'
objSession.Disconnect
Else
'
' Check for Session errors - display message box with error
code
' No error means the user cancelled the connection dialog
box
'
If objSession.Error <> UVE_NOERROR Then
MsgBox "Unable to open connection:- " & objSession.Error
End If
End If
End Sub  

(我可以很好地使用 C# 进行编程。我需要一两个关于如何连接到 Universe 9+ 以及如何在 C# 中实例化我需要的“UniObjects”对象的示例。例如,我知道我需要创建一个会话对象,但 VB 6 代码不会告诉我如何在 C# 中执行此操作...)

【问题讨论】:

  • 如何在 vb6.0 中创建一个与 Universe 9+ 子系统进行所有数据库通信的数据访问程序集...在您的新 C# 应用程序中使用该 dll :)
  • 因为,我相信,这里的目的是继续使用现有的数据库,我会为它实现一个 .Net 数据提供程序。您可能需要像 Hackerman 建议的那样在后台使用 vb6 dll 来执行实际的数据库访问,但是如果您将其包装在 .Net 数据提供程序中,您就可以像使用任何其他 .Net 数据提供程序一样使用它。

标签: c# universe uniobjects


【解决方案1】:

UniVerse 9.6 于 2001 年问世,如果我刚刚找到的自述文件可信的话。这意味着您在那里使用的内容早于 .Net Framework 1.0 版本和商业 C# 的诞生。

您也许可以使用 Ardent ODBC(或其他)驱动程序(如果您能找到它),但您能否成功在很大程度上取决于您的底层数据结构。在我承认的对旧 UV 系统的有限接触中,它们通常不以任何易于处理的方式符合 ODBC 标准。

您可以按照评论者的建议在 VB6 中编写数据库处理程序,但请记住,UniVerse 数据并不总是像大多数人习惯的那样返回漂亮的列数据。在进行这项工作之前,请确保您了解 Universe 的工作原理,否则这可能会是一段漫长且有些痛苦的学习经历。

老实说,我认为您需要退后一步来评估需求。如果它是与旧系统的持续集成,那么您可能会坚持现有的。

如果您只是想获取数据,我会从宇宙角度进行处理。 BASIC 比 VB6 更容易掌握,您可以转储到文件系统并在其他地方加载。

祝你好运。

【讨论】:

    【解决方案2】:

    以下是创建新的 C# 程序以使用 Rocket U2 UniObjects 对象的一些步骤。

    // For the C# program, it need to add the “UniObjects Control 3.0” type library to the project first.
    
    //Create new UniObjects Object .
    UnioaifCtrlClass uniobj = null;
    
    // Set the Object properties.
    uniobj.HostName = “localhost”;
    uniobj.AccountPath = “XDEMO”;
    uniobj.UserName = “user”;
    uniobj.Password = “password”;
    
    //Set UniVerse or UniData database type
    UNIOBJECTSLib.enumDataBaseType dbtype;
    // UniVerse
    dbtype = (UNIOBJECTSLib.enumDataBaseType )1;
    // UniData
    //dbtype = (UNIOBJECTSLib.enumDataBaseType )2;
    uniobj.set_DataBaseType(dbtype);
    
    // Set TCP connection type
    // Network TCP
    UNIOBJECTSLib.enumTransport transportx;
    transportx = (UNIOBJECTSLib.enumTransport)1;
    uniobj.set_Transport(transportx);
    
    // Connect to database  
    bool return_code = uniobj.Connect();
    // Check the return_code
    
    // Test UniObjects Command Object
    UniCommand uocommand= (UniCommand)uniobj.Command;
    uocommand.Text = “LIST VOC”;
    uocommand.Exec();
    // Show result:
    MessageBox.Show(uocommand.Response.ToString());
    
    // Close the session
    uniobj.Disconnect();
    

    【讨论】:

      【解决方案3】:

      没有工具可以自动将 VB6 程序转换为另一个新的 C# 程序。您必须将 VB6 代码逐个代码转换为 C# 代码。 UniObjects COM 对象已被淘汰多年。驱动程序只有 32 位。新的 U2 Toolkit 驱动程序提供了比 UniObjects (UO) 和 UniObjects for .NET (UO.NET) 更多的功能。新驱动程序支持 32 位和 64 位。它还满足了许多安全合规性要求。我建议使用新的 Rocket U2 Toolkit 驱动程序进行相同的转换。

      这是示例代码的一部分。

      - For the C# program, it need to add the “U2.Data.Client” reference to the project first.
      
      - Create new U2 Toolkit Object .
      
              using U2.Data.Client;
              using U2.Data.Client.UO;
              U2Connection u2connect = new U2Connection();
              UniSession u2session;
              UniCommand u2cmd;
      
          - Set the Object properties and connection.
                        Connection_string="server=localhost;Database=XDEMO;UserID=user;Password=pass;Pooling=False;AccessMode=Native;ServerType=UniVerse;RpcServviceType=uvcs";
      
              u2connect.ConnectionString = Connection_string;
              u2connect.Open();
              u2session = u2connect.UniSession;
      
          - Test UniObjects Command Object
              u2cmd = u2session.CreateUniCommand();
              u2cmd.Command = "LIST VOC";
              u2cmd.Execute();
              // Show result:
              MessageBox.Show(u2cmd.Response.ToString(); 
      
          - Close the session
              u2connect.Close();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-29
        • 1970-01-01
        • 2013-03-03
        • 2013-06-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多