jamliu

Receiving "The socket connection was aborted" error exception intermittently in the custom SP2010 webpart using AF SDK

Discussion created by jamliu on Dec 16, 2012
Latest reply on Dec 19, 2012 by jamliu

Hi geeks,

 

   I am working on a custom SharePoint 2010 webpart which pull some AF Attributes by using the AF SDK. Everything appears to be working fine until I tried to login the page with the same accounts but from multiple machines at the same time. By doing so, I intermittently received the "Cannot connect to 'AFServer_Name'" error with the "The Socket connection was aborted ...." inner exception with 10054 error code. However, I never had this issue when login with different accounts from multiple machines though.

 

   It appears the connect was dropped by the WCF at the AF Server side and only when the same accounts are logged in from different machines. I don't know if the AF server is confused by the client's requests and timed out, or something else. I am shooting in the dark and haven't got any luck yet.

 

   In my code (see below), I tried to establish the AF connection, retrieve data, and close connection every time. It seems to be pretty straightforward, but I don't know if I've missed something simple. Thank you guys.

 

 

 

 

 
public class AFDataHandler
{            
        private PISystems _myAFSystems;        
        public PISystem _myAFSystem;
        private AFDatabase _myAFDB;                

        //AF Server and AF SDK variables        
        private string _AFAdminUserLogin = string.Empty;
        private string _AFAdminUserPwd = string.Empty;

        //AF Server 
        private string _AFServerName = string.Empty;
        //AF Database
        private string _AFDBName = string.Empty;        


        public bool connectAF(string strAFServerName, string strAFDBName)
        {
            bool connSuccess = false;

            if (_myAFSystems == null)
            {
                _myAFSystems = new PISystems();
            }  
            
            try
            {
                //Establis the new connection everytime.
               
          _AFServerName = strAFServerName;                  
                          
          //Config the connection credential
          NetworkCredential AFConnCredential = new NetworkCredential();                        
          AFConnCredential.UserName = _AFAdminUserLogin;
          AFConnCredential.Password = _AFAdminUserPwd;                       

          _myAFSystems[_AFServerName].Connect(AFConnCredential);
          _myAFSystem = _myAFSystems[_AFServerName];
          _AFDBName = strAFDBName;
          _myAFDB = _myAFSystem.Databases[_AFDBName];
                    
          _myAFSystem.Refresh();
          _myAFDB.Refresh();
          _myAFSystems.Refresh();
                    
          connSuccess = true;                        
            }
            catch (Exception ex)
            {
                throw ex;                
            }

            return connSuccess;
        }
                
        public bool disconnectAF()
        {            
            bool disconnSuccess = false;
            
           try
           {
               if (_myAFSystem != null)
               {
                   _myAFSystem.Disconnect();               
               }

               _myAFDB = null;
               _myAFSystem = null;
               _myAFSystems = null;
               disconnSuccess = true;
           }
           catch (Exception ex)
           {
               throw ex;
           }    
            
            return disconnSuccess;  
        }
}

 

Outcomes