2

I have database name. I need to get db resource. How? One option I see is to execute Config.Databases:List query and iterate over results till I find required name. After that open db by path and get the resource.

rfg
  • 1,331
  • 1
  • 8
  • 24

2 Answers2

2

If you have only name of the database, you should before get a directory, because SYS.Database works only with directory path.

set dbName="TEST"
if ##Class(Config.Databases).Exists(dbName,.dbconfobj) {
  Set dbObj=##class(SYS.Database).%OpenId(dbconfobj.Directory)
  Set resourceName = dbObj.ResourceName
}

Database directory also you could get in this way

if ##Class(Config.Databases).Get("TEST1",.props) {
  write $get(props("Directory"))
}

Or directory for default database for current namespace

set directory=$zu(12,"")
DAiMor
  • 3,185
  • 16
  • 24
0

You can open database with Set dbObj=##class(SYS.Database).%OpenId("USER") and then get db resource as dbObj.ResourceName. SYS.Database docs and Config.Databases docs.

rfg
  • 1,331
  • 1
  • 8
  • 24
  • in this code `##class(SYS.Database).%OpenId("USER")`, USER - is not a name for database it is a default path and default directory for mgr. Here should be defined full path to database, not name. – DAiMor Jan 21 '16 at 13:50