On 6/4/2013 9:16 PM, Ted Roche wrote:
Oops. Hit 'Send' too soon.


Mike,

Here's my GetHandle routine:

        PROTECTED FUNCTION GetHandle(tlForce as Logical) as Integer
        * Returns connection handle to caller.
LOCAL liHandle as Integer, lcDSN as String, loException as Exception, liRetryCnt as Integer
                IF tlForce OR this.nHandle <= 0 THEN
                        TRY
                                =SQLSETPROP(0, 'DispLogin', 3 ) && suppress 
login info
=SQLSETPROP(0,"ConnectTimeOut",SQLTIMEOUT) && wait N seconds before timeout (mjb 08-04-06)
                                lcDSN = this.cSQLConnect
                                IF NOT EMPTY(lcDSN) THEN
                                        liHandle = SQLSTRINGCONNECT(lcDSN)
IF SQLEXEC(liHandle,[select @@version as cVersion],"curVersion") = 1 THEN
                                                this.cDBCVersion = 
curVersion.cVersion
                                        ELSE && attempt reconnection
                                                liRetryCnt = 1
                                                DO WHILE liHandle < 0 AND 
liRetrCnt <= RETRY_COUNT
WAIT WINDOW TIMEOUT .5 "Re-attempting (" + ALLTRIM(STR(liRetryCnt)) + ") to connect to SQL database..."
                                                        liHandle = 
SQLSTRINGCONNECT(lcDSN)
IF SQLEXEC(liHandle,[select @@version as cVersion],"curVersion") = 1 THEN
                                                                
this.cDBCVersion = curVersion.cVersion
                                                        ELSE
MESSAGEBOX(this.cSystemName + " is unable to establish connection to the database.",16,"Unable to connect.")
                                                                liHandle = -99
                                                        ENDIF
                                                        liRetryCnt = liRetryCnt 
+ 1
                                                ENDDO
                                        ENDIF
                                ELSE
                                        liHandle = -1
                                ENDIF
        
                        CATCH TO loException
                                liHandle = -1
MESSAGEBOX(loException.Message,16,"Problem getting handle. " + ADMINMSG)
                        ENDTRY
                        this.nHandle = liHandle

                ELSE
                        * mjb 02-04-08 verify that it's good
IF SQLEXEC(this.nHandle,[select @@version as cVersion],"curVersion2") = 1 THEN && alright, good to go
                                liHandle = this.nHandle
                        ELSE && force new handle via recursive call
                                WAIT WINDOW NOWAIT "Reattempting to connect..."
                                liHandle = this.GetHandle(.T.)
                        ENDIF
                ENDIF && tlForce OR this.nHandle = 0
                
                * done with temp cursors
                USE IN SELECT("curVersion")
                USE IN SELECT("curVersion2")

                RETURN liHandle
        ENDFUNC && GetHandle() as Integer



--
Mike Babcock, MCP
MB Software Solutions, LLC
President, Chief Software Architect
http://mbsoftwaresolutions.com
http://fabmate.com
http://twitter.com/mbabcock16

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to