0

我正在使用一个多值数据库,该数据库目前正在使用 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# 中做到这一点......)

4

3 回答 3

1

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

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

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

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

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

祝你好运。

于 2016-12-01T23:49:30.780 回答
0

以下是创建一个新的 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();
于 2016-12-07T20:25:39.637 回答
0

没有工具可以自动将 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();
于 2016-12-08T17:53:50.753 回答