SQL connection help

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf SQL connection help

  • Creator
    Topic
  • #52811
    hari nagasamudra
    Participant

      hello,

      I have this TCL script (just the piece posted) and trying to connect to the external server.

      set err [odbc SQLAllocHandle SQL_HANDLE_ENV SQL_NULL_HANDLE henv]

      echo “SQLAllockHandle:$err”

      odbc SQLSetEnvAttr $henv SQL_ATTR_ODBC_VERSION SQL_OV_ODBC3 0

      set err [odbc SQLSetEnvAttr $henv SQL_ATTR_ODBC_VERSION SQL_OV_ODBC3 0]

      echo “SQLSetEnvAttr:$err”

                 

      # allocate a connection handle

                 

      odbc SQLAllocHandle SQL_HANDLE_DBC $henv hdbc

      set err [odbc SQLAllocHandle SQL_HANDLE_DBC $henv hDBConnection]

      echo “SQLAllocHandle:$err”

      # allocate a statement handle

      odbc SQLAllocHandle SQL_HANDLE_STMT $hdbc hstmt

      set err [odbc SQLAllocHandle SQL_HANDLE_STMT $hdbc hstmt]

      echo “SQL_HANDLE_STMT:$err$hstmt”

      set err [odbc SQLPrepare $hstmt $sqlStmt SQL_NTS]

      echo “SQLPrepare:$err”

      set err [odbc SQLExecute $hstmt]

      # $sqlStmt SQL_NTS]

      echo “SQLExecDirect:$err”

      and I get the following error.

      SQLAllockHandle:SQL_SUCCESS

      SQLSetEnvAttr:SQL_SUCCESS

      SQLAllocHandle:SQL_SUCCESS

      SQL_HANDLE_STMT:SQL_ERRORhstmt0

      [0:TEST] Tcl error:

      msgId = message0

      proc = ‘odbcHARI’

      args = ”

      result = ‘hstmt is not open

      handle hstmt0 not found’

      errorInfo: ‘

      hstmt is not open

      handle hstmt0 not found

         while executing

      “odbc SQLPrepare $hstmt $sqlStmt SQL_NTS”

         (“run” arm line 21)

         invoked from within

      “switch -exact — $mode {

             start {

                 # Perform special init functions

                 odbc SQLAllocHandle SQL_HANDLE_ENV SQL_NULL_HANDLE …”

         (procedure “odbcHARI” line 17)

         invoked from within

      “odbcHARI {MSGID message0} {CONTEXT sms_ib_data} {ARGS {}} {MODE run} {VERSION 3.0}”‘

      Do we need to exclusively OPEN the connection? I feel like I am missing one important thingy. ANY HELP IS MUCH APPRECIATED.

      thanks,

      Hari

    Viewing 0 reply threads
    • Author
      Replies
      • #75547
        Daniel Lee
        Participant

          I think after your SQLAllocHandle SQL_HANDLE_DBC where you allocate the database handle, you’ll need to connect to the database before you create your statement handle.

          set errcode [odbc SQLConnect $hdbc SQL_NTS SQL_NTS SQL_NTS]

      Viewing 0 reply threads
      • The forum ‘Cloverleaf’ is closed to new topics and replies.