SQLitening Support Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Welcome to the SQLitening support forums!

Author Topic: Auto Switching and Uploading  (Read 73 times)

Fredrick Ughimi

  • Master Geek
  • ****
  • Posts: 601
    • View Profile
    • Software Development Company
Auto Switching and Uploading
« on: December 05, 2018, 01:48:34 AM »

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?
Logged
Fredrick O. Ughimi

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

Fredrick Ughimi

  • Master Geek
  • ****
  • Posts: 601
    • View Profile
    • Software Development Company
Re: Auto Switching and Uploading
« Reply #1 on: December 06, 2018, 02:43:42 AM »

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.
Logged
Fredrick O. Ughimi

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

cj

  • Master Geek
  • ****
  • Posts: 696
    • View Profile
Re: Auto Switching and Uploading
« Reply #2 on: December 06, 2018, 01:31:11 PM »

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
« Last Edit: December 06, 2018, 01:51:30 PM by cj »
Logged
CJ

cj

  • Master Geek
  • ****
  • Posts: 696
    • View Profile
Re: Auto Switching and Uploading
« Reply #3 on: December 06, 2018, 02:06:08 PM »

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
« Last Edit: December 06, 2018, 02:19:14 PM by cj »
Logged
CJ

Fredrick Ughimi

  • Master Geek
  • ****
  • Posts: 601
    • View Profile
    • Software Development Company
Re: Auto Switching and Uploading
« Reply #4 on: December 07, 2018, 05:46:25 AM »

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.

Logged
Fredrick O. Ughimi

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