Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How are you using the Session Class?
Message
 
 
À
09/12/1999 17:36:13
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00300919
Message ID:
00301726
Vues:
35
>>>I use it to create my initial shared connection to an Oracle database.
>
>Sounds like a very interesting application of Session. Care to "share" some example code?

Certainly. The following code has been slightly modified for the sole purpose of this question.
procedure OraLogin
*
local oVTS, llRetVal, lcTsoID, lcPassword
*-- The user table is already open in the default DS and is at
*-- the record for the user logged in. This is based on their
*-- Novell login ID verified using NetLib 3rd party library.
*-- The user table has a field for the Novell login ID and their
*-- Oracle user ID [TsoID] which unfortunately is not the same.
lcTsoID = VTS_User.TsoID
oVts = NewObject("Login", "VTS.vcx")
oVts.txtUserId.Value = lcTsoId
oVts.Show()
*-- oVts.lValid is set to True if user provided all login info
*-- and did not cancel the login. Their is no verification the
*-- the data entered is correct.
llRetVal = oVts.lValid
lcPassword = alltrim(oVts.txtPassword.Value)
oVts.Release()
release oVts
if !llRetVal
	return llRetVal
endif

*-- Application object, oApp, was created earlier in the App

oApp.mResetError()			&& clears last error array property of oApp
local lcOldError, llLoginError
lcOldError = on("error")
on error llLoginError = .t.		&& defensive programming only

select VTS_User
llRetVal = flock("Vts_User")
do while !llRetVal			&& needed because of upcoming DBSetProp code
	inkey(0.04, "H")
	llRetval = flock("Vts_User")
enddo

oApp.addproperty('oSession')
oApp.oSession = newobject('session')
local lnDSID
lnDSID = oApp.oSession.DataSessionID

set datasession to lnDSID
set database to vts			&& SETs are scoped to DS
set talk off

*-- The following prevents the Oracle Login form from appearing.
*-- While the UserId and Password are temporarily stored in the
*-- DBC, the locking of the VTS_User table prevents these from
*-- getting stepped on. The process is so quick, the risk of
*-- someone here having a developer version of VFP running and
*-- issuing a DBGetProp to steal the ID and Password is acceptible
*-- [about nil]. The only people who have access to the Novell
*-- directory where the DBC and data reside is limited to the users
*-- and LAN Admins. Therefore, this is a secure and acceptible process.

dbsetprop('sdwisfed','connection','connectstring','DSN=SDWIS/Fed;UID=' + lcTSOID + ';PWD=' ;
	+ lcPassword + ';SERVER=sdwisfed;')

use VTS!OracleConnection

*-- Next line removes the UID and Password from the DBC

dbsetprop('sdwisfed','connection','connectstring','')

local llUsed
llUsed = used("OracleConnection")
if llUsed
	*-- Store the Connection Handle for use in SPT
	oApp.ConnectHandle = CursorGetProp("ConnectHandle", "OracleConnection")
endif

set DataSession to			&& revert back to default DS
unlock in Vts_User			&& now other users can login

if !empty(lcOldError)
	on error &lcOldError
else
	on error
endif

if !llUsed or llLoginError
	*-- Another possibility is the Oracle database may not be available [down].
	messagebox("Invalid User ID or Password. Login terminated.", MB_ICONSTOP, "FATAL ERROR!")
	oApp.oSession = .null.
	return .f.
endif

*-- I have some other Login setup stuff here, but it is irrelevent to the question

return .t.
*-- End procedure OraLogin

*-- In your App cleanup process or otherwise kill the session, all you have to add is:

oApp.oSession = .null.
Mark McCasland
Midlothian, TX USA
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform