AW: Reconnecting to Valentina after timeout

Thorsten Hohage thohage at objectmanufactur.com
Thu Jan 17 04:03:51 CST 2008


Hi,

to feed you with some REALworking code ;-) here we go


For all DB operations I use one "DB-Context" object so it is easy to  
maintain code and to connect to different DBs (but who want to do this  
when knowing Valentina)

ALL my methods doing DB operations / access starts with

	if ValentinaREConnect then


and this method is defined

	if not(myValentinaDB.IsOpen) then
		Me.Connect()
	end if
	Return true


It's now small again, but before I used it for several loggings and  
checkings before, so the code still exist as a method and it would be  
good to keep it separate if I feel the need to do more here again.

myValentinaDB as VDatabase,  Server, User, Password, Port,  
V4RBDebugLevel are object properties

Please note that using the Server variable to switch between local  
file usage and connection to a VServer!


The Connect() Method is defined as

	Dim dbFile As FolderItem
	Dim errorMsg As String
	Dim myConnection As VConnection
	Dim dummy As Integer
	Dim portInt As Integer


	  if myValentinaDB = nil or not myValentinaDB.IsOpen then

// I need to check here both conditions again, because I logged two  
times a situation where between ValentinaREConnect and this line the  
DB is already re-connected due to another object ... I know it  
shouldn't be, but it is possible in RB?!?!?

     	errorMsg = ""

     		
	if DatabaseName.len = 0 then
		errorMsg =  "Fatal Failure: No Database-Name!"

	else //DatabaseName.len = 0

		if InStr(Server, ".vdb") > 0 or InStr(Server,".file")>0 then
		        ' using  file
			Valentina.Init(1 * 1024 *1024, *SERIALS*)
			Valentina.DebugLevel = V4RBDebugLevel

			myValentinaDB = new VDatabase(1)
			dbFile = GetFolderItem("database")
			if dbFile <>nil then
				dbFile = dbFile.Child(Replace(Server,".file",""))
			end if

			if dbFile = nil or not(dbFile.Exists) then
				errorMsg =  "Fatal Failure: Specified Server or File not Found!"
			end if

		else
         		' using server
			Valentina.Init(1 * 1024 *1024)
			Valentina.InitClient(64)

			Valentina.DebugLevel = V4RBDebugLevel
			portInt = val(Port)

			myConnection = new VConnection(Server, User, Password, portInt,  
10,*SERIAL*)

		        try
				myConnection.Open()
				myValentinaDB = New VDatabase(myConnection)

			Catch VException
           			errorMsg = *ERROR HANDLING HERE*
			end try
			dbFile = GetFolderItem(DatabaseName)
		end if

		if errorMsg = "" then
			try
				if dbFile <>nil then
					myValentinaDB.Open( dbFile)
					myValentinaDB.DateFormat = EVDateFormat.kYMD
				else
					errorMsg = "Fatal Failure: Specified Server or File not Found!"
				end if

			catch VException
				errorMsg = *ERROR HANDLING HERE*
			end try
		end if

	end if //DatabaseName.len = 0


HTH


regards

Thorsten Hohage
--
objectmanufactur.com - Hamburg,Germany



On 2008-01-17, at 10:37, Ruslan Zasukhin wrote:

> On 17/1/08 9:31 AM, "Ivan Smahin" <ivan_smahin at paradigmasoft.com>  
> wrote:
>
>> Hello Fabian,
>>
>> Thursday, January 17, 2008, 9:18:38 AM, you wrote:
>>
>>> Hi Ivan,
>>
>>> I don't think that this is what I mean.
>>> My Connection to the server is closed (timeout after 20 minutes  
>>> inactivity).
>>> I want to reconnect, but dbconnection.open seems not to be enough.
>>> Dbconnection.isconnected returns true then but I cannot access the  
>>> database.
>>
>> It  would  not  work this way. There are always pair of objects -  
>> stub
>> and proxy which are living on the client and server side  
>> respectively and
>> working together.
>> Closing  connection  (never mind who initiate it) leads to destroy  
>> all
>> proxy objects for this connection in the server. So stubs are not  
>> able
>> to communicate to the server and must be destroyed also.
>
> In other words, you need kill your existed objects, and repeat  
> procedure of
> connect as first time.


More information about the Valentina mailing list