Connecting to UniObjects via .NET using UODOTNET

This tutorial assumes you've installed UniDK and have access to the  UODOTNET.dll. The dll should be available from C:\IBM\UniDK\uonet\bin.

This tutorial will use Visual Studio to connect to a UniVerse database.

Start by opening Visual Studio and creating a new Windows Forms Appicaltion.


Next you can choose to add a button to connect and one to disconnect. I'm also adding a Label in order to tell us whether the connection is active or deactivated.

Now go and view your Form1 code (F7). Next add the UODOTNET.dll into your References.
Right-click References > Add Reference > Browse... > C:\IBM\UniDK\uonet\bin > Select UODOTNET.dll > Click OK. Your References should now include the UODOTNET.dll

Next picture shows you the a sample of how to connect. You'll need 5 parameters to send the UniObjects class OpenSession() method. You can also specify a port if needed.

Server / Hostname - The name or network address of the instance of U2 Database to which to connect.
Username - U2 Database login name
Password - U2 Database login password
Account - The name of the U2 Database Account
Service - The name of U2 Database service as defined in "unirpcservices" file. Server installation creates the following entries in "unirpcservices" file: "defcs" for the default service, "uvcs" for Universe , "udcs" for Unidata

Your code should look something like this. Just add your credentials in the empty strings.


Start you application and click our Connect button. If the label changes to green, you're connected, if not the credentials might be wrong. The following errors should help you find the problem.

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 192.168.2.1:31438 - This usually means an incorrect server or hostname.

[IBM U2][UODOTNET - UNICLIENT][ErrorCode=80011] The user name provided is incorrect - Check spelling of username

[IBM U2][UODOTNET - UNICLIENT][ErrorCode=80019] The password provided is incorrect - Check spelling of password

[IBM U2][UODOTNET - UNICLIENT][ErrorCode=39129] The account name supplied is not a valid account - Luckily these error are quite self-explanatory.

UniRPCConnection failed to establish a connection with the remote host.[IBM U2][UODOTNET - UNIRPC][ErrorCode=81002] No RPC Connection active. Source: UniRPCConnection Class Method: Void ConnectInternal(Int32)   at IBMU2.UODOTNET.UniRPCConnection.ConnectInternal(Int32 responseIndex)

   at IBMU2.UODOTNET.UniSession.Connect() - Incorrect service used. I think there is only 3 valid services to choose from, "defcs","uvcs","udcs".

The next part of our code is the disconnect button code. This is the proper way to disconnect from the UniVerse server.

 That's it. A simple way (hopefully) to connect to Universe DB using UniObjects.

Comments

Popular posts from this blog

Using Telerik RadProgressArea

Dates in UniVerse Basic