• Welcome, Guest. Please login.
 
October 25, 2021, 08:34:20 PM

News:

Welcome to the SQLitening support forums!


SLEEP after disconnect using remote server

Started by cj, December 03, 2012, 06:33:39 PM

Previous topic - Next topic

cj

December 03, 2012, 06:33:39 PM Last Edit: December 03, 2012, 06:35:52 PM by cj
Without a SLEEP after a disconnect it is possible to receive an error 23 "VERSON CONFLICT".
This was done in remote mode using threads.  SLEEP 500 seems to fix the problem.


#DIM ALL
#COMPILE EXE "\sql\bin\ConnectTest.exe"
#INCLUDE "\sql\inc\SQLitening.Inc"
%SleepAfterDisconnect = 0

%Connections   = 20
$IP = "192.168.1.2"
%PortNumber = 51234

FUNCTION PBMAIN AS LONG
  slSetProcessMods "E0"

  LOCAL x, result AS LONG, hThread AS DWORD
  FOR x = 1 TO %Connections
    THREAD CREATE Connector(x) TO hThread
    SLEEP 50 'required to let connections allocate
    THREAD CLOSE hThread TO result
    IF result = 0 THEN ? "Thread close error" + STR$(ERRCLEAR) 'never occurs
  NEXT
  ? "Click to end program"
END FUNCTION

THREAD FUNCTION Connector(BYVAL x AS LONG) AS LONG
  LOCAL result AS LONG
  result = slConnect($IP,%PortNumber)
  IF result = 0 THEN
    slDisconnect
    IF %SleepAfterDisconnect THEN SLEEP 500
    EXIT FUNCTION
  ELSE
    BEEP
    ? "Thread" + STR$(x)+ "  Connect error " + slGetError  'error 23
  END IF
END FUNCTION


cj

December 03, 2012, 07:04:49 PM #1 Last Edit: December 03, 2012, 07:06:35 PM by cj

SUB slDisconnect ALIAS "slDisconnect" EXPORT
'   Disconnects from the server.  This is optional.  A connection will
'   be automatically disconnected when your program ends. If you are done
'   with a connection but your program will continue to run for some time
'   then it is a good idea to disconnect.  Also needed if running remote
'   and you now want to start running only local. No error will occur.

   LOCAL lhRutAddr AS DWORD

   ' Init stuff
   RESET tlLastError

   ' Only use if we are connected.
   IF tuFlags.AreConnected THEN

      ' Close all open sets
      irCloseAllSets

      ' Disconnect from server
      irGetRutAddress "SQLiteDisconnect", lhRutAddr
      CALL DWORD lhRutAddr

      ' Clear running remote, set access mode to neutral,
      ' clear that we are connected, and clear sqlite-file handle
      RESET tuFlags.AreRunningRemote, thSQLiteLibHand, tuFlags.AreConnected, thDab
      SLEEP 350
   END IF

END SUB                   

cj

December 03, 2012, 07:16:54 PM #2 Last Edit: December 03, 2012, 07:18:31 PM by cj
Added WAITFORSINGLEOBJECT hThread,%INFINITE  and error 23 "VERSON CONFLICT" returned.


#DIM ALL
#COMPILE EXE "\sql\bin\ConnectTest.exe"
#INCLUDE "\sql\inc\SQLitening.Inc"
#INCLUDE "win32api.inc"

%Connections   = 20
$IP = "192.168.1.2"
%PortNumber = 51234

FUNCTION PBMAIN AS LONG
  slSetProcessMods "E0"

  LOCAL x, result AS LONG, hThread AS DWORD
  FOR x = 1 TO %Connections
    THREAD CREATE Connector(x) TO hThread
    SLEEP 50 'required to let connections allocate
    WaitForSingleObject hThread,%INFINITE
    THREAD CLOSE hThread TO result
    IF result = 0 THEN ? "Thread close error" + STR$(ERRCLEAR) 'never occurs
  NEXT
  BEEP
  ? "Click to end program",,EXE.NAME$
END FUNCTION

THREAD FUNCTION Connector(BYVAL x AS LONG) AS LONG
  LOCAL result AS LONG
  result = slConnect($IP,%PortNumber)
  IF result = 0 THEN
    slDisconnect
    EXIT FUNCTION
  ELSE
    ? "Thread" + STR$(x)+ "  Connect error " + slGetError  'error 23
  END IF
END FUNCTION



                       

cj

Error -23 occurs if using WAITFORSINGLEOBJECT and perhaps other thread functions on second connection.
By not checking for -23 on the connection seems to work.


#DIM ALL
#COMPILE EXE "\sql\bin\ConnectTest.exe"
#INCLUDE "\sql\inc\SQLitening.Inc"
#INCLUDE "win32api.inc"
%WaitForSingleObject = 1 'create error 23 on second connection
GLOBAL g_Error23_Count AS LONG

%Connections   = 8   '-23 errors are 1 less than this if %WaitForSingleObject
$IP = "192.168.1.2"
%PortNumber = 51234
%MaxTries = 4

FUNCTION PBMAIN AS LONG
  slSetProcessMods "E0"
  REM  %SQLitening_VersionConflict  = -23  - SQLitening.Dll, SQLiteningClient.Dll, and SQLiteningServer.Exe

  LOCAL x, result AS LONG
  DIM hThread(%Connections) AS DWORD
  FOR x = 1 TO %Connections
    THREAD CREATE Connector(x) TO hThread(x)
    SLEEP 50
    #IF %WaitForSingleObject
    WAITFORSINGLEOBJECT hThread(x), %INFINITE
    #ENDIF

  NEXT
  ? "Error -23 occurred"  + STR$(g_Error23_Count)+ " times.",,EXE.NAME$
  FOR x = 1 TO %Connections
    IF hThread(x) THEN THREAD CLOSE hThread(x) TO result
  NEXT
END FUNCTION

THREAD FUNCTION Connector(BYVAL x AS LONG) AS LONG
  LOCAL result,Attempt AS LONG
  FOR Attempt = 1 TO %MaxTries
    result = slConnect($IP,%PortNumber)
    IF result = 0 OR Result = -23 THEN
      IF result = -23 THEN INCR g_Error23_Count
      slDisconnect
      EXIT FOR
    END IF
    BEEP
    SLEEP 500
  NEXT

END FUNCTION

cj

December 04, 2012, 12:46:07 PM #4 Last Edit: December 04, 2012, 12:48:51 PM by cj
If the program above is run from the PB 10 editor  then five or seven error -23's are returned.
If a shortcut to the exe or the program is run from a command line  three -23's are returned.
Very strange.

Fred Meier

December 06, 2012, 10:40:47 AM #5 Last Edit: December 06, 2012, 11:56:54 AM by Fred Meier
I experienced the problem in LocalHost remote mode and working on solution.

There was flaw in the irGetDllFileVersion routine in SQLiteningClient when using threads.
For unknown reason the iif$ PB command would fail on not first calls.
I also changed the irGetMyExeFileVersion routine in SQLiteningServer.

Version 1.60.5 has been posted