Database AScript - PostOpen event Issue

We have a DB with replica’s on 3 servers. We want to force people to use Server A so I wrote some Database Script in the PostOpen event. Basically the script checks to see if the database the user is trying to open is the one on Server A. If so, then open it. If not then see if Server A DB can be opened and if it can then open the database on server A and close the database the user tried to access, let’s say Server B. In this case, the script is running on Server B.

This works great if the Client is 6.0.3, when we try openning the db on ServerB it opens the DB on Server A and closes the db on server B.

When we try it on a 7.0.2 Client. It Starts to run the Script and the Status bar says “Script is busy” and then it crashes the Notes Client. If we try to open the DB on server A it opens with no problem, only when we try to open it on server B and it redirects it to server A.

The code was developed on 6.0.3 Designer

The servers are 6.0.2 CF1

Here is my code:

Dim thisServer As String

Dim thisDbPath As String

Dim prodServerAName As String

Dim prodServerBName As String

Dim drServerName As String

Sub Postopen(Source As Notesuidatabase)

'01/05/2007 (mdz) this script checks the current server and if it is “DR Server” then it will attempt to open the

'production database on “Server A”. If open is successful then it redirects the user to the production replica

'and closes the source database and also removes the icon on the desktop for the offending database.

removeIcon = False 'this will flag to remove the Icon being used if set to true

Dim ws As New NotesUIWorkspace

Dim ses As New NotesSession

Dim uidb As NotesUIDatabase

Dim thisdb As NotesDatabase

Dim prodDBA As New NotesDatabase ("","")

Dim prodDBB As New NotesDatabase ("","")

Dim configDoc As NotesDocument

Dim nam As NotesName

Dim repID As String, msgTitle As String, message As String

'setup Notes Stuff

Set uidb = source

Set thisdb = uidb.Database

Set nam = ses.CreateName(thisDB.Server)

Set configDoc = thisDb.GetProfileDocument("Systemdoc")

'get replica of Db and try to open the Production Database

repID = thisDb.ReplicaID    'used to find replica on production server

thisServer = nam.Abbreviated

thisDbPath = thisDB.filePath

'get the names of the servers from the system document

prodServerA = configDoc.GetItemValue("prodServerA")  	'first production copy

prodServerAName = prodServerA(0)

prodServerB = configDoc.GetItemValue("prodServerB") 	'second Production Server

prodServerBName = prodServerB(0)

DRServer = configDoc.GetItemValue("drServer") 				'disaster recovery server

drServerName = DRServer(0)



If thisServer = prodServerAName Then Exit Sub  'it is the production server so allow access



If thisServer = prodServerBName Then   'it is on the 1st backup server

'check availablity of production database on production server

	If ProdDbA.OpenbyReplicaID(prodServerAName,repID) Then  'production is up and running

		Call uidb.Close  'close the original database used

		Call ws.OpenDatabase(ProdDbA.Server,ProdDbA.filePath,"(All Docs)")  'open the production database

		Set thisDB = Nothing

		Set ProdDb = Nothing

		Exit Sub  'done with script

	Else

		Exit  Sub  'allow access to the current database

	End If

End If



If thisServer = drServerName Then      'then it is on the disaster recovery server     

'try to open production db based on source db replica id, then try 1st backup server after that.

'If both are down then allow access to DR Db.

	If ProdDbA.OpenbyReplicaID(prodServerAName,repID) Then  'production is up and running

		removeIcon = True

		

		Call uidb.Close  'close the original database used

		Call ws.OpenDatabase(ProdDbA.Server,ProdDbA.filePath,"(All Docs)")  'open the production database

		Set thisDB = Nothing

		Set ProdDbA = Nothing

		Set ProdDbB = Nothing

		Exit Sub  'done with script

	Elseif  ProdDbB.OpenbyReplicaID(prodServerB(0),repID) Then  'production server down - check for 1st back up server

		removeIcon = True

		Call uidb.Close  'close the original database used

		Call ws.OpenDatabase(ProdDbBB.Server,ProdDbB.filePath,"(All Docs)")  'open the 1st backup database

		Set thisDB = Nothing

		Set ProdDbA = Nothing

		Set ProdDbB = Nothing

		Exit Sub  'done with script

	Else

	'looks like both Server A and Server B are down - open the DR server replica

	End If

End If

Goto EndofCode

EndOfCode:

End Sub

  • Mike

Subject: Database AScript - PostOpen event Issue

I apparently had posted this before ( http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/5659b718db94199c852573af007354fc?OpenDocument ) and I changed some of the code (I was removing the icon from the desktop but not anymore) and it started working in 6.0.3. It still works in 6.0.3 but now doesnt work in 7.0.2.

Would like to get it to work in 7.0.2.