Brad,
I have PFW programs that write thousands of SQL Server transactions every day using ODBC SQL Server. I open the database when first starting the program and then pass the variables back and forth as required. The following four code items are stored at the form level for my main application form.
In summary:
- I defined a custom type in the Type() event
- I defined some form level variables
- I created the method openProgramFiles() to collect parameters and open the database (This also opens my custom SQLLIB library that contains the rest of my re-usable SQL related code)
- I updated the form open() event to call openProgramFiles()
- Remember to close the database on the form's close() event.
At the form level:
Type
varArray = dynarray[] anytype
strarray = array[] string
endType
Var
sqldbname, appDBname string
rdb database
dbparmsDA dynarray[] anytype
customLib, sqlLib library
outputArray vararray
endVar
method open(var eventInfo Event)
if eventInfo.isPreFilter() then
;// This code executes for each object on the form:
else
;// This code executes only for the form:
if not openProgramfiles()
then disableDefault
errorclear()
close()
endif
endif
endmethod
method openProgramFiles() logical
var
tc tcursor
currentSes session
newpass string
endvar
currentSes.open()
newpass = "XXXXX"
currentses.addPassword(newPass)
if not tc.open(":CUSTOMAPP:LOGIN.DB")
then msgInfo("Error Starting Program",
"Unable to open table with login data. Call Technical Support")
return false
endif
tc.movetorecord(1)
outputArray["DB User Name"] = tc."user_name"
outputArray["DB Password"] = tc."user_password"
outputArray["DB Alias Name"] = "SQLDATA"
outputArray["Application Alias Name"] = "CUSTOMAPP"
CustomLib.PassArray(outputArray)
tc.close()
appDBName = outputArray["Application Alias Name"]
sqlDBName = outputArray["DB Alias Name"]
dbParmsDA["USER MODE"] = "READ/WRITE"
dbParmsDA["USER NAME"] = outputArray["DB User Name"]
dbParmsDA["PASSWORD"] = outputArray["DB Password"]
;Test Opening the SQL database
try rdb.open(sqldbname, dbparmsDA)
onfail
msgInfo("Error Opening SQL database",
"Unable to open SQL database for setting up program.\nAborting procedure")
errorshow()
return false
endtry
rdb.close()
;Open the SQL library
if not sqllib.open(":L:SQLLIB")
then
msgInfo("Error Opening Library",
"Unable to open SQLLIB library.\nAborting procedure")
errorshow()
rdb.close()
return false
endif
return true
endmethod
---
Bradley Wood