4

I have some (limited) experience with UniData and UniVerse databases and now wanting to work with them via the .NET framework. It appears that the way to work with them now is via Rocket Software's U2 Toolkit for .NET.

Since I will be accessing databases whose schemas I won't know a priori, I need to know how to query the databases not just for data (that will come later), but for information about the databases themselves, such as the names of existing tables and their schemas.

It looks like maybe Rocket (or maybe it was IBM who owned the U2 technology previously) has some of that functionaity built into some of their utilities, but I really need to be able to do this programatically.

Any ideas?

ksigmund
  • 527
  • 1
  • 6
  • 13

2 Answers2

5

You can access U2 Database (UniData or UniVerse) using U2 Toolkit for .NET the following ways:

  1. SQL Access (UCI Server)
  2. Native Access (UO Server)

SQL Access

For SQL Access, you need to normalize U2 Account (getting schema). For this, you can use the following tools:

  1. HS.ADMIN (for UniVerse Database) (http://www.rocketsoftware.com/u2/products/u2-clients-and-db-tools/u2-resources/universe-11.1-clients/copy_of_uvodbc-v11r1.pdf/view)
  2. VSG (for UniData Database)
  3. MDM ( for UniVerse Database and UniData Database)

You can use U2 Toolkit for .NET’s U2 Database Provider for .NET (ADO.NET Provider) for SQL access

Native Access

For Native Access, you do not need to do anything.

You can use U2 Toolkit for .NET’s UO API for Native Access.

Sample Code and MSDN Style Help

There are tons of sample code on SQL Access and Native Access when you install the product.

The best thing for you is to install U2 Toolkit for .NET V 1.2.1 and start developing some code. You can run almost all samples as it uses sample database ( ‘HS.SALES’ UniVerse Account and ‘demo’ UniData Account)

You can also read U2 Toolkit for .NET V 1.2.1’s MSDN Style Help for information such as Architecture, Account Accessible/Getting Schema, Sample Code etc.

enter image description here

I have tested U2Connection Class’s GetSchema() with UniData’s demo account. It works for me. See screen shot below.

enter image description here

private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            U2ConnectionStringBuilder conn_str = new U2ConnectionStringBuilder();
            conn_str.UserID = "user";
            conn_str.Password = "pass";
            conn_str.Server = "localhost";
            conn_str.Database = "demo";
            conn_str.ServerType = "UNIDATA";
            conn_str.Pooling = false;
            string s = conn_str.ToString();
            U2Connection con = new U2Connection();
            con.ConnectionString = s;
            con.Open();
            this.textBox2.AppendText("Connected......."+Environment.NewLine);
            this.textBox2.AppendText("CALLING .......   DataTable dt = con.GetSchema(\"Tables\");"+Environment.NewLine);
            DataTable dt = con.GetSchema("Tables");
            this.dataGridView1.DataSource = dt.DefaultView;
            con.Close();
                        }
        catch (Exception e2)
        {

            this.textBox2.AppendText(e2.Message);
        }
    }

It looks like your ‘demo’ account is not normalized. Can you run “sql> select * from SQLTables;” from TCL Command. Do you see the following? If not, then you can do one of the following:

  1. Run VSG Tool (Read VSG Manual)
  2. Run MDM Tool (Read MDM Manual)
  3. Run Command line from TCL Command:

     o    Convert.sql STUDENT (Read Unidata  Manual for convert.sql command)
     o    Grant privilege
     o    MIGRATE.SQL
    

enter image description here

Rajan Kumar
  • 718
  • 1
  • 4
  • 9
  • Rajan - thank you for your help. This certainly has me headed in the right direction. I've successfully connected to my local database, but the specific thing I'm looking for (i.e. to programatically get a list of all tables) still eludes me. I'm thinking I need to use the GetSchema() method, but when I pass it U2MetaDataCollectionNames.Tables, I get no rows back. This is being run against the demo Unidata database. – ksigmund May 24 '13 at 06:03
  • Please see my answer above. – Rajan Kumar May 26 '13 at 04:48
  • Thanks again, Rajan. I've head better luck using UniVerse. Maybe this is worthy of a new question, but is there any way to determine which tables returned by the GetSchema method are subtables of other tables? For instance, in HS.SALES, there's a CUSTOMER table which contains, I believe an MV_ORDERS table. When calling GetSchema, two of the tables are CUSTOMER (which makes sense) and CUSTOMER_ORDERS. Can I infer their relationship based on a naming convention? – ksigmund May 27 '13 at 05:14
  • Yes, you can. But in this case, HS.SALES is normalized account. That's why you see CUSTOMER and CUSTOMER_ORDER Tables. – Rajan Kumar May 28 '13 at 16:12
  • It sounds like, and correct me if I'm wrong, there's no good way to get a DataTable (or other structure) that communicates the heirarchy, as it were, of a U2 database. Ultimately, I'd like to render the structure of the database (i.e. "main" tables, mulitvalue, and sub-multivalue tables) in a tree-like structure. I'm a little wary of doing this based on naming convention. Am I missing something obvious here? As of now, what I see is a list of tables, all at the same level, in the DataTable and it's up to me to figure it out. I feel like there must be some way to do this using the API. – ksigmund May 28 '13 at 16:57
  • It is easy if your account is normalized. First call GetSchema("Tables") , then call GetSchema("Cloumns", table name). It will give you tree like view. You can also see VS2010/VS2012 Server Explorer where you have connection->tables->columns. That's what you are looking for. You do not need to use naming convention as tool does for you. – Rajan Kumar May 28 '13 at 20:28
  • Thanks for the reply. Part of my challenge is that this is meant to inquire upon a database whose schema is unknown until runtime, so the Server Explorer tool doesn't help me. Calling GetSchema on Tables and then on Columns make sense to me, however, I need to know how the tables are related to one another. So, besides, naming conventions, is that possible at runtime? I'm open to using UniCommands, etc. to be able to figure this out. – ksigmund May 28 '13 at 21:20
  • If you are using UniCommands, it means you are going 'Native' way. In this case, you will see Files and Attributes using some commands and subroutines. – Rajan Kumar May 29 '13 at 02:46
  • I do understand the difference between the native way vs. the higher-level API, but I'd like to know how to get a list of each table and their respective subtables/relationships. Is there a way to do this? – ksigmund May 29 '13 at 04:00
  • For tables and their relationship, you can use U2Connection Class's GetSchema() API with normalized U2 account. – Rajan Kumar May 29 '13 at 15:08
  • Among the results I get doing that are the CUSTOMER and CUSTOMER_ORDER tables, as I mentioned earlier. However, there appears to be no way to determine their association (i.e. that CUSTOMER_ORDER has essentially a foreign key into CUSTOMER). ` U2Connection con = new U2Connection(); con.ConnectionString = s; con.Open(); var tables = con.GetSchema(U2MetaDataCollectionNames.Tables);` I get back five tables, two of them being the ones I mention earlier. Both have empty ParentRelations and ChildRelations properties; where else I can look in the resulting DataTable to figure this out? – ksigmund May 29 '13 at 16:23
  • `U2Connection con = new U2Connection(); con.ConnectionString = s; con.Open(); var tables = con.GetSchema(U2MetaDataCollectionNames.Tables);` – ksigmund May 29 '13 at 16:47
  • try "PrimaryKeys" and "ForeignKeys" for the relation in GetSchema() API. – Rajan Kumar May 29 '13 at 18:57
  • PrimaryKeys returns the following (TABLE_NAME, COLUMN_NAME, KEY_SEQ) `CUSTOMER_ORDERS @ASSOC_ROW 2` `STATES CODE 1` `CUSTOMER_ORDERS CUSTID 1` `CUSTOMER CUSTID 1` `PRODUCTS PRODID 1` ForeignKeys returns no results. This is all on the HS.SALES database, which ships with the personal edition. – ksigmund May 29 '13 at 20:04
  • Yes, I can reproduce this issue. We have to fix this. Could you please create a U2 Issue stating that ForeignKey return empty table when we use GetSchema(). – Rajan Kumar May 29 '13 at 20:48
  • Who do I contact to open an issue? – ksigmund May 29 '13 at 22:19
  • contact U2 Askus Mailbox , they will help you. – Rajan Kumar May 29 '13 at 23:41
  • This issue is resolved. You will get it in next U2 Toolkit for .NET Release. – Rajan Kumar Jun 12 '13 at 04:50
  • Thanks, Rajan. Any idea when this is being released? – ksigmund Jun 24 '13 at 03:33
  • Thank You. For this information, please contact U2 Askus Mailbox – Rajan Kumar Jun 26 '13 at 12:44
  • I was told that this ultimately wasn't resolved in the latest release. Is this your understanding, Rajan? – ksigmund Dec 10 '13 at 18:48
  • It is resolved in U2 Toolkit for .NET v1.3.0. I will post screen shot and C# code very soon. – Rajan Kumar Dec 11 '13 at 20:00
  • See below screen shot. Make sure you are using v1.3.0. You can verify using log file. We write version number in log file. For example : Assembly File Version:1.3.0.1375 – Rajan Kumar Dec 12 '13 at 01:25
  • Is v1.3.0 available for public download? – ksigmund Dec 12 '13 at 15:20
  • Yes, Please ask U2 Askus Mailbox for website link. – Rajan Kumar Dec 12 '13 at 15:23
  • @RajanKumar do you know how to do pagination with universe and .net driver? commands like offset next do not work :-( – Bhupendra May 18 '17 at 03:29
1

U2 Toolkit for .NET v1.3.0 supports "ForeignKeys" and "ForeignKeysColumns" in GetSchema() API. See below Fig1, Fig2, Fig3 and Fig4.

Fig1

Fig2

Fig3

Fig4

Rajan Kumar
  • 718
  • 1
  • 4
  • 9
  • Rajan, I can call the parameterless GetSchema() method, but when trying to use your code above, I get the following: [U2][UCINET-UO] [U2][UCINET][UNIVERSE]:"*HS.OLEDBINFO" is not in the CATALOG space. – ksigmund Jan 15 '14 at 20:25
  • Can you run your app as an administrator? What is your UniVerse Version? What is the OS (UniVerse)? Did you install v1.3.0? I have never seen this error before. – Rajan Kumar Jan 17 '14 at 03:25
  • I contacted u2askus@rocketsoftware.com and apparently there is a problem with the latest installer of UniVerse PE. UniData PE seems OK. – ksigmund Jan 17 '14 at 15:42