Thamer Alenazi

Forum Replies Created

Viewing 2 replies – 1 through 2 (of 2 total)
  • Author
    Replies
  • in reply to: ODBC process hangs and stops processing #73961
    Thamer Alenazi
    Participant

      Jason Garrant wrote:

      There are a limited number of connections you can make at one time.

      in reply to: ODBC process hangs and stops processing #73959
      Thamer Alenazi
      Participant

        Yes Davis I’m connecting and disconnecting to DB for each message.

        Have a look to my script

        proc Venus_Interface { args } {

           global HciConnName

           keylget args MODE mode               ;# Fetch mode

           keylget args CONTEXT ctx

           keylget args ARGS uargs

           set rcList

      •    set debug         “0”       ; keylget uargs DEBUG   debug

           # The parameters needed to connect to the database

           set dsnName       “ICIS_Interface” ; keylget uargs DSNNAME dsnName

           set dsnUser       “venus” ; keylget uargs DSNUSER dsnUser

           set dsnPass       “venuS2OO9” ; keylget uargs DSNPASS dsnPass

           # The parameters needed to stop the thread

           set processName   prod_receiver    ; keylget uargs PROCESSNAME processName

           set threadName    bhandler   ; keylget uargs THREADNAME  threadName

           # Module string for debugging purposes

           set module “$HciConnName/[lindex [info level 0] 0]/$ctx”

           set dispList {} ;# Nothing to return

           switch -exact — $mode {

               start {

                   # Perform special init functions

                   # N.B.: there may or may not be a MSGID key in args

                   if { $debug } {

                       echo “($module): Start using settings: $uargs”

                   }

               }

               run {

         # ‘run’ mode always has a MSGID; fetch and process it

                   # Initiate connection to the database

                   # Set an i variable to count the number of tries for connecting to DB

                   # Sleep 5 seconds between every two tries

                   keylget args MSGID mh

                   set i 1

                   set trialNum 3

                   set sleepPeriod 5

                   set dhList [datlist]

        set enc “cp1256”

        set gh [grmcreate -msg $mh hl7 2.3 hnam.hl7 {}]

        set msgcontent [msgget $mh]

        set msgcontent [encoding convertfrom $enc $msgcontent]

        regsub -all ‘ $msgcontent ” msgcontent

        #puts stdout “…$msgcontent”

                  #Trying To connect to the Database (ICIS_Interface)

                  while { [catch {lassign [gc_dbConnect $dsnName $dsnUser $dsnPass $debug] henv hdbc} err] } {

                      puts stderr “[fmtclock [getclock] %c] $err”

                       if { $i > $trialNum } {

                           #Could not connect to the DB

                           puts stderr “$module: Tried connecting $trialNum times in $mode mode. Giving up.”

                           puts stderr “Error: Check the connection string in: thread outbound settings, J2EEFUNCTIONS settings”

                           puts stderr “Error: If set properly, check that the data source is defined in odbc.ini file”

                           #set repmh [venus_constructReply $gh AE]

                           set dispList “KILL $mh”

                           #lappend dispList “SEND $repmh”                    

                           return $dispList

                       }

                       # Inform about the inability to connect and sleep for sleepPeriod (e.g. 5 seconds)

                       puts stderr “$module: Connection failure in attempt $i. Retrying in 5 seconds…”

                       sleep $sleepPeriod

                       incr i

                   }

                   #puts stdout “We have succeeded connecting…”

               set cmd “insert INTO MSG_QUEUE (MSG,CONTROL_ID) values (N’$msgcontent’,’P’)”

        set cmd [encoding convertto utf-8 $cmd]

                   

        ;#####################################here

        if { [catch {

                # Allocation of handler

                 puts stdout “$module: Doing SQLAllocHandle: [odbc SQLAllocHandle SQL_HANDLE_STMT $hdbc hstmt]”

                 # puts stderr “The command was: $cmd”

                 # Try to execute the command that contains the function call

                 # If you catch an error stop the thread and echo it

                 # Else validate the reply

                  if { [catch {set rc [odbc SQLExecDirect $hstmt $cmd SQL_NTS]} err] || [lsearch -exact $rcList $rc] < 0 } {

                               catch {append err “n[gc_dbGetODBCError $henv $hdbc $hstmt $debug]”}

                               puts stdout “Error: Could not execute the command, check your command”

                               puts stdout “Error: The Commeand was $cmd”

                               puts stdout “$module: Doing SQLExecDirect: $err”

                               } else {

                                 #puts stdout “$module: Doing SQLExecDirect: $rc and the reply is $reply”

           

                   #


        CONSTRUCTING REPLY


                   set repmh [venus_constructReply $msgcontent AA]

                                 }

           

                               # Free the handle for the statement execution

                               puts stdout “$module: Doing SQLFreeHandle: [odbc SQLFreeHandle SQL_HANDLE_STMT $hstmt]”

                               } err] } {

                                  puts stderr “$module: Dramatic error $err”

                               }

                   #


        CLEANUP


                   # FREE handler, destroy grm.

                   catch {odbc SQLFreeHandle SQL_HANDLE_STMT $hstmt}

                   catch {grmdestroy $gh}

                   catch {hcidatlistreset $dhList}

             

                   # Disconnect from the database

                   gc_dbDisconnect $henv $hdbc

                   #


        DISPOSITIONING


                   # Specify the disposition

                   lappend dispList “KILL $mh”

                   lappend dispList “SEND $repmh”

               }

               time {

                   # Timer-based processing

         # N.B.: there may or may not be a MSGID key in args

               }

               

               shutdown {

                   # Doing some clean-up work

               }

           }

           return $dispList

        }

        Thanks

      Viewing 2 replies – 1 through 2 (of 2 total)