private static void OpenAMOServerConnection(object o) { ConnectAMOServerInfo info = null; try { info = (ConnectAMOServerInfo)o; Microsoft.AnalysisServices.Server s = new Microsoft.AnalysisServices.Server(); s.Connect(info.ConnectionString); info.Server = s; } catch (Exception ex) { info.ex = ex; } finally { info.autoEvent.Set(); } }
/// <summary> /// Returns an open connection to an AMO server /// Connection is opened on a background thread /// Helps ensure a sproc trying to open an AMO connection does not get deadlocked /// </summary> /// <param name="ConnectionString"></param> /// <returns></returns> public static Microsoft.AnalysisServices.Server ConnectAMOServer(string ConnectionString) { ConnectAMOServerInfo info = new ConnectAMOServerInfo(); info.ConnectionString = ConnectionString; info.autoEvent = new System.Threading.AutoResetEvent(false); System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(OpenAMOServerConnection), info); while (!info.autoEvent.WaitOne(1000, false)) { Context.CheckCancelled(); //if the parent query has been cancelled (or the ForceCommitTimeout expires) then this will immediately exit } if (info.ex != null) { throw info.ex; } else { return(info.Server); } }