Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Datalogger auto-REconnection for PostgreSQL
#1
Hi all, i have a simple QM application that needs to store data 24h/24 on a PostGreSQL.
I have an ODBC entry in system DSN named POS_ENM.
Connection between my QM application and PostGreSQL work very well but i like to try to autoreconnect my application to database if the server goes down.

Function dlg_autoconnect
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

Database+ db
str result
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 135 "Dialog"
;3 Edit 0x54030080 0x200 68 18 96 14 "cstatus"
;4 Edit 0x54030080 0x200 68 38 96 14 "dsn"
;1 Button 0x54030001 0x4 120 116 48 14 "OK"
;2 Button 0x54030000 0x4 170 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2030407 "" "" "" ""

str+ dbsource
str controls = "3 4"
str e3cst e4dsn
if(!ShowDialog("dlg_autoconnect" &dlg_autoconnect &controls)) ret

ret
;messages
sel message
,case WM_INITDIALOG
,dbsource.from("DSN=POS_ENM")
,db.Open(dbsource)
,,err
,,,out _error.description
,SetTimer hDlg 1 1000 0                        ;;Start a timer to check if database is connected
,case WM_TIMER
,if !db                                        ;;Verify if database is connected
,,db.Open(dbsource)                        ;;If not connected try to reconnect
,,err
,,,out _error.description
,,result.from("Not Connect")
,,result.setwintext(id(3 hDlg))
,,dbsource.setwintext(id(4 hDlg))
,else
,,result.from("Connect")
,,result.setwintext(id(3 hDlg))
,,dbsource.setwintext(id(4 hDlg))

,case WM_DESTROY
,KillTimer hDlg 1
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1


is there a way to check to do this?
Thank's


Alessandro


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)