Db.open

Help - can anyone tell me why this script is not opening the specified database please

Dim strDataDict As String

Dim strDataDictFilePath As String

strDatadict = “cpdatadic.nsf”

strDataDictFilePath = Replace(strFilePath ,strFileName,strDatadict)

Call dbDataDict .Open(session.currentDatabase.server, strDataDictFilePath)

Subject: Db.open

In the code sample provided you haven’t declared the session, the values of strFilePath and strFileName aren’t specified, and there’s a space between dbDataDict and .Open(…

Without knowing what the values of strFilePath and strFileName are I can’t be sure why you are using Replace to get the database path name.

I’d be tempted to break the code down a bit more and write something like this:

Dim sess as New NotesSession

Dim db as NotesDatabase

Dim svr as String

Dim dbpath As String

Set db = sess.CurrentDatabase

svr = db.Server

dbpath = “directory\subdirectory\cpdatadic.nsf”

If Not db.IsOpen Then

Call db.Open ( svr , dbpath )

End If

hth

Ian

Subject: RE: Db.open

This is the the bit of code that was missing

Dim session As New NotesSession

Dim dbManDef As NotesDatabase             

Dim docManDef As NotesDocument 

Dim viewManDef As NotesView

Set dbManDef = session.CurrentDatabase

Dim strFilePath As String

Dim strFileName As String

Set  viewManDef = dbManDef.GetView("warning")

Set docManDef  = viewManDef. GetFirstDocument

'Get the File path and the File name of the Current Notes database

'This is needed to open the Data Dictionary and Systems Definitions databases

strFilePath = dbManDef.FilePath											

strFileName = dbManDef.FileName	

'Data Dictionary Notes things

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

Dim docDataDict As NotesDocument 

Dim viewDatadict As NotesView

'Replace file name of the filepath string with cpdatadic.nsf

Dim strDataDict As String

Dim strDataDictFilePath As String

strDatadict = "cpdatadic.nsf"

strDataDictFilePath  = Replace(strFilePath ,strFileName,strDatadict)	

Call dbDataDict .Open(session.currentDatabase.server, strDataDictFilePath)

Subject: RE: Db.open

On the last line you still have the space between dbDataDict and .Open(…

Subject: RE: Db.open

Ian I have corrected that error but still get the error about database has not opened yet

Subject: RE: Db.open

A very simple step would be to not call the db.Open method, but assign its return value to a boolean variable.

If it returns false, the database cannot be found at that location. For whatever reason.

There was a bug on 5.04, that lead to the Domino Directory becomming unaccessible using LotusScript after a while. The only workaround was to shut down the server, compact names from the comand line and fire up the server again. Since then, I’ve never heard of a general problem like that. Taking Ian’s suggestions into account, your code looks OK.

Subject: RE: Db.open

On the line that states:Set docManDef = viewManDef. GetFirstDocument

There’s a space between Def. and GetFirstDocument

Maybe that’s a typo. What I’d do though is check that you actually get a handle on the document as follows:

Set docManDef = viewManDef.GetFirstDocument

If Not docManDef Is Nothing Then

strFilePath = dbManDef.FilePath

strFileName = dbManDef.FileName

End If

End Sub

Subject: DEBUG IT

try turning on the debugger, and before stepping into the line that says open the database, look to see if all of the necessary objects and variables are set as you expect them to be.

Subject: RE: Db.open

  1. First, this line of code is too much:

Call dbDataDict .Open(session.currentDatabase.server, strDataDictFilePath)

You already have set the database to the current database, so it just needs to be:

Call dbDataDict .Open(dbManDef.server, strDataDictFilePath)



  1. You need to do a boolean test as someone stated elsewhere in this thread:

if dbDataDict.isopen then

Do your stuff

else

Messagebox “Unable to open database”

End if

If you are getting this it means one of two things:

a. The signer of the agent (or the person running it if manual) does not have proper access to the database.; or

b. The database does not exist in that path.

You are better off having profile documents that store the needed databases and a field containing their replica ID (without the “:”). That way you do not need to worry about where the database is stored:

Dim dbDataDict As New NotesDatabase(“”,“”)

if dbDataDict.openbyreplicaID then

  Do your stuff 

else

  Messagebox "Unable to open database"

End if

NOTHING like this kind of information should be hard coded in script or formulae.



  1. Think about rearranging the way you code your script so it flows like someone would read it without having to hunt through code to find where things are set:

Dim session As New NotesSession

Dim dbManDef As NotesDatabase

Set dbManDef = session.CurrentDatabase

'GET THE APPLICATION PROFILE DOCUMENT

Dim viewAppProfiles as NotesView

set viewAppProfiles=dbManDef.getView(“luvaAppProfiles”)

dim docAppProfile as Notesdocument

set docApprofile=viewAppProfiles.getdocumentbyKey(_

“Data Dictionary”,true)

if not (docApprofile is nothing) then

Dim viewManDef As NotesView

Set viewManDef = dbManDef.GetView(“warning”)

Dim docManDef As NotesDocument

Set docManDef = viewManDef. GetFirstDocument

Dim dbDataDict As New NotesDatabase(“”,“”)

If dbDataDict.OpenByReplicaID( dbDataDict.server, _

  docApprofile.ReplicaID(0)) Then



  Dim viewDatadict As NotesView

  set viewDataDict=dbDataDict.getview_

      (docApprProfile.LookupView(0)



  Dim docDataDict As NotesDocument

   etc etc)


Hope this helps…

Subject: Db.open

db.Open does not open a database to appear on screen, if this is what you are after. It is “opened” for full backend access to all of it’s properties and methods.

To display a database, you have to use frontend methods that display a view, document, form, frameset, whatever.

Subject: RE: Db.open

I need to open it in the backend but I get the error message saying the database has not been opened yet !