示例#1
0
 /// <summary>
 /// 是否连接实时库
 /// </summary>
 /// <returns></returns>
 public Boolean Connection()
 {
     try {
         String serverName = ConfigurationManager.AppSettings["PIServer"];
         //格式:"UID=kkk;PWD="
         String userNameAndpassword = ConfigurationManager.AppSettings["PIConnectionString"];
         if (null == dbConnector) {
             dbConnector = new DbConnector();
         }
         dbConnector.ServerName = serverName;
         String userName = String.Empty;
         String password = String.Empty;
         GetUserIDAndPwd(userNameAndpassword, out userName, out password);
         dbConnector.UserName = userName;
         dbConnector.Password = password;
         dbConnector.TimeOut = 10;  //超时时间,单位为秒
         if (null != dbConnector && dbConnector.IsConnected()) {
             tagTree = TagTree.CreateInstance(dbConnector);
             tagManager = tagTree.GetMgr();
             rootNode = tagTree.GetTreeRoot();
             return true;
         }
         DbError error = dbConnector.Connect();
         if (error.HasErrors) {
             _ErrorInfo = "pSpaceApi类Connect函数出错:" + error.ErrorMessage + ",错误编码为: " + error.ErrorCode;
             return false;
         }
         tagTree = TagTree.CreateInstance(dbConnector);
         tagManager = tagTree.GetMgr();
         rootNode = tagTree.GetTreeRoot();
         return true;
     }
     catch (Exception e) {
         _ErrorInfo = "pSpaceApi类Connect函数异常:" + e.Message + " $$$ " + e.StackTrace;
         return false;
     }
 }