首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Universe 9+ system,UniObjects (不适用于.NET) -如何将示例从VB6转换为C#

Universe 9+ system,UniObjects (不适用于.NET) -如何将示例从VB6转换为C#
EN

Stack Overflow用户
提问于 2016-12-01 23:05:49
回答 3查看 475关注 0票数 0

我正在使用一个多值数据库,该数据库目前正在使用IBM U2 (现在的Rocket software )的UniObjects软件连接到宇宙9.+系统。这不是火箭软件公司为宇宙10+和11+系统推出的针对.NET的UniObjects。我要尝试连接到宇宙9+系统的唯一示例是使用Visual basic6.0,并且我需要使用C#。谁能告诉我如何在C#中连接到一个宇宙9+系统?基本上,我正在尝试将我在VB6中使用的东西转换到C#上,以便连接到那个系统。感谢您所能提供的一切帮助。文档中的一些示例如下所示:

代码语言:javascript
复制
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#很好地编程。我需要的是一个或两个关于如何连接到宇宙9+以及如何在C#中实例化我需要的"UniObjects“对象的示例。例如,我知道我需要创建一个session对象,但VB6代码不会告诉我如何在C#中做到这一点……)

EN

回答 3

Stack Overflow用户

发布于 2016-12-02 07:49:31

如果我刚刚找到的自述文件可信的话,UniVerse 9.6是在2001年发布的。这意味着您在那里使用的内容早于.Net Framework1.0发布和商业C#的诞生。

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

您可以按照评论者的建议,用VB6编写一个数据库处理程序,但请记住,UniVerse数据并不总是像大多数人习惯的那样返回很好的柱状数据。在你开始这项工作之前,请确保你了解宇宙是如何工作的,否则这可能是一个漫长而有些痛苦的学习经历。

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

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

祝好运。

票数 1
EN

Stack Overflow用户

发布于 2016-12-08 04:25:40

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

代码语言:javascript
复制
// 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();
票数 0
EN

Stack Overflow用户

发布于 2016-12-09 01:53:51

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

以下是示例代码的一部分。

代码语言:javascript
复制
- 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();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40913964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档