K2 Connection object, when K2 server unavailable


Badge +3

We have our intranet site calling a K2 server and opening a connection on our main page via an asp.net control.  Sometimes our K2 service has an issue or the service needs to be restarted and we need a way that when opening a Connection to the K2 server the code doesn't sit there and hang.  Since there is no timeout on the K2 Connection object does anyone have any suggestions on how to make a call to the K2 server using the Connection object and if within a second it doesn't respond just return from the call.  Otherwise the call causes the main page to hang when creating the control.  I guess I'm looking for a why for the connection object to have a timeout like a .net SqlConnection object does.


 Thanks in advance,


 Scott


2 replies

Badge +6

You can use the overload constructor for Connection with the ConnectionSetup object which has a timeout property, or just add timeout to your connectionstring such as:


Integrated=False;IsPrimaryLogin=True; Authenticate=True;EncryptedPassword=False; Host={0};Port=5252;UserID={1};Password={2};TimeOut=20


This is just one example connection string, but you get the idea. :)

Badge +3

Thanks, that's what I was looking for.  I ended up doing the following and it was what we needed:


 using (Connection K2Con = new Connection())


{


ConnectionSetup K2ConSetup = new ConnectionSetup();


K2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.Host, ConfigurationManager.AppSettings["K2Server"]);


K2ConSetup.ConnectionParameters.Add(ConnectionSetup.ParamKeys.TimeOut, ConfigurationManager.AppSettings["K2ConnTimeOut"]);


//Open a connection to the K2[blackpearl] server


K2Con.Open(K2ConSetup);


K2Con.ImpersonateUser(Profile.GetValue(

"WindowsLogin"));


nameLabel.Text = K2Con.User.Name;


Worklist K2WorkList = K2Con.OpenWorklist("ASP");


K2Con.RevertUser();


 ... more code


K2Con.Close()


}


 

Reply