• Welcome, Guest. Please login.
 
April 24, 2019, 09:31:36 am

News:

Welcome to the SQLitening support forums!


Auto Switching and Uploading

Started by Fredrick Ughimi, December 05, 2018, 03:18:34 am

Previous topic - Next topic

Fredrick Ughimi

Hello,

Wondering if these two scenarios could work. Program running over the internet with the client machines having their own database as well.

1. Automatically switch between Local and Remote access depending on the availability of internet connection. If internetconnection do remote else do local.

2. Automatically upload records entered in local database to the remote server when the internet connection is available.

Are these scenarios feasible?
Fredrick O. Ughimi

fughimi@yahoo.com
- Freedom lies in being bold -- Robert Frost, Poet

Fredrick Ughimi

Not sure if the applies here.

https://www.sqlitening.planetsquires.com/index.php?topic=3204.msg16315#msg16315

Quote
Yes, you can switch back and forth between local and remote mode by using
slPushDatabasae, slSetProcessMods, and slPopDatabase.  Look at ExampleA.Bas
and study the L modchar in slSetProcessMods.

The below does a connect, switches to local mode, gets the data from a local
file and then switches back to remote mode.
Code: [Select]
   slConnect
   slPushDatabase
   slSetProcessMods "L0"
   slGetFile "Your file name here", YourStringVariable
   slPopDatabase
   slSetProcessMods "L1"


Would give it a shot.
Fredrick O. Ughimi

fughimi@yahoo.com
- Freedom lies in being bold -- Robert Frost, Poet

cj

December 06, 2018, 03:01:11 pm #2 Last Edit: December 06, 2018, 03:21:30 pm by cj
If you slPushDatabase the current database is no longer available until you slPopDatabase
Be careful if connection fails, etc.

This might work just as well without rotating database handle
1 IF can't get to host then no need to push and pop database handles
2 If can get to host then disconnect, read local log, reconnect, send local log
Sounds like good planning like no cloud no work.

Did this way to try to avoid lots of IF statements.

After looking at it awhile workinglocal  and workingremote would need to duplicate code.
The program would probably need to use IF gconnect to share the routines.

#DIM ALL
#INCLUDE "sqlitening.inc"
GLOBAL gConnect AS LONG
'-------------------------------------------------------
FUNCTION PBMAIN () AS LONG
LOCAL x,ecode,portnumber AS LONG
LOCAL sHost AS STRING
slSetProcessMods "E0"

sHost = "192.168.0.13"
PortNumber = 80

FOR x = 1 TO 1 'try multiple times to connect
  ecode = slConnect(shost,portnumber)
  IF ecode = 0 THEN gConnect = 1:EXIT FOR ELSE BEEP
NEXT
IF gConnect THEN
  WorkingRemote
ELSE
  IF MSGBOX("Could not connect, work local?",%MB_YESNO OR %MB_SYSTEMMODAL,"Connect error") = %IDYES THEN
   WorkingLocal
  ELSE
   ? "Ending the program",%MB_SYSTEMMODAL,"Thank you"
  END IF
END IF

END FUNCTION
'-------------------------------------------------------
SUB WorkingLocal
? "Local routines create log"
END SUB
'-------------------------------------------------------
SUB WorkingRemote
slDisconnect
? "Connected/Disconnected"
END SUB

cj

December 06, 2018, 03:36:08 pm #3 Last Edit: December 06, 2018, 03:49:14 pm by cj
I don't think slpushdatabase and slpopdatabase will help much
The big thing is keep the databases in sync and how to prevent duplicate keys from being rejected.
I'm thinking like an ATM machine can't give out money if central server is down.
One thing about cloud computing is the data is duplicated and maintained by different locations.
Some may not know that they have to pay for that duplicated data if sent to different servers.
Is cloud safer and more secure?  Yes, in my opinion.  Sorry for getting off subject.

#DIM ALL
#INCLUDE "sqlitening.inc"
GLOBAL gConnect AS LONG
'-------------------------------------------------------
FUNCTION PBMAIN () AS LONG
LOCAL x,ecode,portnumber AS LONG
LOCAL sHost AS STRING
slSetProcessMods "E0"

sHost = "192.168.0.12"
PortNumber = 80

FOR x = 1 TO 1 'try multiple times to connect
  ecode = slConnect(shost,portnumber)
  IF ecode = 0 THEN gConnect = 1:EXIT FOR ELSE BEEP
NEXT
IF gConnect = 0 THEN
  IF MSGBOX("Could not connect, work local?",%MB_YESNO OR %MB_SYSTEMMODAL,"Connect error") = %IDNO THEN
   ? "Ending the program",%MB_SYSTEMMODAL,"Thank you"
   EXIT FUNCTION
  END IF
END IF

IF gConnect THEN
  slDisconnect
  ? "disconnect and end"
ELSE
  ? "end"
END IF
END FUNCTION

Fredrick Ughimi

Hello CJ,

Thanks as always.

Both samples code works good. I think I would go with the second one. I did something similar to that earlier.

The tricky part is:
Quote
2. Automatically upload records entered in local database to the remote server when the internet connection is available.


The client computers are multiple, not just one.

Fredrick O. Ughimi

fughimi@yahoo.com
- Freedom lies in being bold -- Robert Frost, Poet