Tuesday, September 1, 2015

OnBase Unity C# Visual Studio: Create an ODBC connection

Core to creating an OnBase Visual Studio application is to connecting to and querying the onbase database instance for various activities outside of what the API exposes. Here are the steps to do this:


  1. Install the ODBC driver for your OnBase database
  2. Configure a Data Source Name entry
  3. Import the ODBC class for reference
  4. Write code to establish a connection object
  5. Open a connection
  6. Run through the results
  7. Close a connection
Here's some of the code to help do this:

... main code


                OdbcConnection conn = openODBCConnection();
                OdbcDataReader dr = null;
                OdbcCommand cmd = null;

                cmd = new OdbcCommand("select a.keyvaluechar from keyitem141 a  " +
                "where a.itemnum = '" + itemnumtemp + "'", conn);

                dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    TempValue = dr[0].ToString().Trim();
                }

                conn.Close();
                cmd.Dispose();
                dr.Dispose();

... connection method
                 conn.ConnectionString = "DSN=OnBaseDSN;UID=hsi;PWD=password"

4 comments:

  1. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. This comment has been removed by the author.

      Delete
  2. This comment has been removed by the author.

    ReplyDelete