简体   繁体   中英

Universe 9+ system, UniObjects (not for .NET) - How to convert examples from VB 6 to C#

I am working with a multi-value database that is currently using IBM U2 (now Rocket Software)'s UniObjects software to connect to a Universe 9.+ system. This is not UniObjects for .NET as put out by Rocket Software for Universe 10+ and 11+ systems. The only examples I have to use to try to connect to the Universe 9+ system are using Visual Basic 6.0 and I need to use C#. Can anyone show me HOW to connect to a Universe 9+ system in C#? Basically, I'm trying to translate what I would use in VB 6 over to C# in order to connect to that system. Thanks for any and all help you can provide. Some of the examples in the documentation are as follows:

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  

(I can program very well with C#. What I need is an example or two on how to connect to Universe 9+ and how to instantiate what "UniObjects" objects I need in C#. I know for instance that I need to create a session object, but VB 6 code won't tell me how to do that in C# ...)

UniVerse 9.6 came out in 2001, if the Readme file I just found is to be believed. That means that what you are using there predates the .Net Framework 1.0 release and the birth of commercial C#.

You might be able to use the Ardent ODBC (or some other) driver (if you can find it) but your success with that is going to depend heavily on your underlying data structure. In my admittedly somewhat limited exposure to old UV systems, they generally don't conform to ODBC standards in any kind of easy to deal with way.

You could do as the commenters suggest and write a database handler in VB6, but bear in mind that UniVerse data does not always return pretty columnular data like most people are used to. Make sure that you understand how Universe works before you undertake this endeavour as it will likely be a long and somewhat painful learning experience otherwise.

I think honestly you need to step back an evaluate the need. If it is a continuing integration with an old system, you are probably stuck with what you have.

If you are just trying to get the data off, I would work it from the Universe angle. BASIC is much easier to grok than VB6 and you can dump to the filesystem and load it elsewhere.

Good luck.

Here are some steps to create a new C# program to work with Rocket U2 UniObjects Object.

// 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();

There is no tool to convert a VB6 program to another new C# program automatically. You must convert the VB6 code to C# code by code. The UniObjects COM object has been phased out for many years. The driver is only 32-bit. New U2 Toolkit driver has provided more features than UniObjects (UO) and UniObjects for .NET (UO.NET). New driver is 32-bit and 64-bit support. It also meets with a lot of security compliance requests. I suggest to use new Rocket U2 Toolkit driver with same conversion effort.

Here is the part of sample codes.

- 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM