我有2个数据库,一个包含XPages(移动Web应用程序,让我们称之为数据库A),另一个包含文档(数据库b)。在我的测试单元中,一切正常。当我访问移动Web应用程序时,它可以完美地访问数据库B中的数据。但是当我在客户端的服务器中安装它们时,Web应用程序无法访问数据库b。我检查了所有ACL条目,我认为没关系。页面上的错误:
Error while executing JavaScript computed expression Script interpreter error, line=161, col=18: 'ecrDB' is null at [/sjs_common.jss].getCRViewDetails()
导致错误的脚本是:
function getCRViewDetails(){ 158: 159: var ecrDB:NotesDatabase = ECR().mainDB; 160: var viewDetails:Array = new Array(); 161: if(ecrDB.isOpen()){ //----- HERE IS THE ERROR LINE! 162: //var vw:NotesView = ecrDB.getView("Drafts"); 163: var vw:NotesView = ecrDB.getView(mainConstants.VIEW_MAIN); 164: var docs:NotesDocumentCollection = vw.getAllDocumentsByKey(session.getEffectiveUserName(), true) 165: //var doc:NotesDocument = vw.getFirstDocument(); 166: var doc:NotesDocument = docs.getFirstDocument(); 167: while(doc != null){ 168: viewDetails.push([ 169: doc.getItemValueString("ProjectTitle"), 170: doc.getItemValueString("CRNumber"), 171: doc.getUniversalID() 172: ]); 173: //print(doc.getItemValueString("ProjectTitle") + ">>" + doc.getItemValueString("CRNumber")); 174: //doc = vw.getNextDocument(doc); 175: doc = docs.getNextDocument(doc); 176: } 177: }
这是我访问数据库b(ECRDB)的方式:
function ECR(){ 34: 35: //private properties and methods --------------------------------- 36: 37: //Setup document 38: var SetupDoc:NotesDocument = database.getProfileDocument("(Setup)",""); 39: 40: // try to connect to Main DB if the sessionScope.ECRMainDBPath has been set 41: if(sessionScope.containsKey("ECRMainDBPath") && sessionScope.containsKey("ECRDataRepPath")){ 42: try{ 43: var ECRDB:NotesDatabase = session.getDatabase( 44: SetupDoc.getItemValueString("ECRMainServer"), 45: sessionScope.get("ECRMainDBPath"), 46: false); 47: var DataRep:DataRepository = new DataRepository( 48: session.getDatabase(SetupDoc.getItemValueString("ECRMainServer"), 49: sessionScope.get("ECRDataRepPath"), 50: false)); 51: 52: var ecrSettingsDoc:NotesDocument = ECRDB.getProfileDocument("eCRSettings",""); 53: }catch(e){ 54: print(e.message); 55: print("Error: Cannot access eCR Main. Please check if Anonymous is at least Reader Access"); 56: ECRDB = null; 57: } 58: }else{ 59: //TODO put this in init() 60: if(!(view.getPageName().equals("/login.xsp") || view.getPageName().equals("/selectDivision.xsp"))){ 61: context.redirectToPage("selectDivision.xsp"); 62: } 63: } 64: 65: return { 66: test : "Hello Orga!", 67: 68: setupDoc : SetupDoc, //get Setup Document 69: 70: getSetupValue : function(fieldName){ 71: return this.setupDoc.getItemValueString(fieldName); 72: }, 73: 74: //get ECR Main database (content database) 75: mainDB : ECRDB, 76: 77: //get eCRSettings doc from the Main DB 78: mainSettings : ecrSettingsDoc, 79: 80: //get full database path (with server) 81: getFullDBPath : function(){ 82: return this.mainDB.getServer() + "!!" + this.mainDB.getFilePath(); 83: }, 84: 85: //get Data Repositoy Object 86: getDataRep : function(){ return DataRep; }, 87: 88: //get Data Repository //TODO remove this 89: //dataRep : DataRep.getDatabase(), 90: 91: //get URL for Data Repository 92: //getDataRepURLPath : DataRep.getURLPath, 93: 94: getDBURL : function(){ 95: return context.getUrl().toString().split(view.getPageName())[0]; 96: }, 97: 98: getSplittedOrder : function(){ 99: return this.mainSettings.getItemValueString("SplittedOrder"); 100: } 101: }; 102: }// end of ECR declaration
我不知道数据库可能存在的问题是什么。你能告诉我为了成功访问数据库b需要检查哪些因素?非常感谢你! :)
答案 0 :(得分:0)
只有当此陈述为真时,您的ECRDB变量才会初始化:
sessionScope.containsKey("ECRMainDBPath") && sessionScope.containsKey("ECRDataRepPath")
在调用ECR()函数之前,请仔细检查sessionScope变量。