Why does ADOMD.NET connection sometimes doesnt open?

1.2k views Asked by At

I have created a webservice which gives access to data from Microsoft Analysis Services Cube. I wanted to see how webservice will perform so i generated simple console app, which generated 'x' Threads and each thread makes 'y' requests to the webservice.

console app:

 static int counter = 0;
        static void Main(string[] args)
        {
            WaitCallback callBack;

            callBack = new WaitCallback(RunAsync);
            for (var i = 0; i < 7; i++)
            {
                Console.WriteLine("openeed thread:" + i);
                ThreadPool.QueueUserWorkItem(callBack, i);
            }
            Console.ReadLine();
        }

        private static void RunAsync(object state)
        {
            for (var i = 0; i < 200; i++)
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri("http://localhost:49425/");
                    client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", "some data");
                    var x = client.GetAsync('URL');

                    if (x.Result.IsSuccessStatusCode)
                    {
                        var result = x.Result.Content.ReadAsAsync<float>();
                    }
                    Interlocked.Increment(ref counter);
                    Console.WriteLine(counter + " Thread : "+ state + " # request " + i);
                }
            }
        }
    }

And here is the mathod which is called on the webservice:

public float GetTurnover(Guid ClientUid, int startDate, int endDate)
    {
        float returnValue = 0.0f;
        var cn = new AdomdConnection();
        cn.ConnectionString = Constants.CubeConnectionString;
        try
        {
            var open = Task.Run(() => cn.Open());
            Task.WaitAll(open);
        }
        catch
        {

        }


        var mdxQuery = new StringBuilder();
        // string test = @"some query";

        using (var command = new AdomdCommand(query, cn))
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Amount", typeof(float));

            try
            {
                var data = command.ExecuteReader();
                dt.Load(data);
                var close = Task.Run(() => cn.Close());
                Task.WaitAll(close);
                float.TryParse(dt.Rows[0].ItemArray[1].ToString(), out returnValue);

                return returnValue;
            }
            catch
            {

            }
            return returnValue;
        }

this line : var open = Task.Run(() => cn.Open()); is breaking sometimes after 100-150 requests which is not consistent. I have increased # of simultanious connection both on IIS and Cube, but it dont seem to help.

Any ideas what is breaking?

EDIT

Stacktrace :

Microsoft.AnalysisServices.AdomdClient.AdomdConnectionException was unhandled by user code
  HResult=-2146233088
  Message=The connection either timed out or was lost.
  Source=Microsoft.AnalysisServices.AdomdClient
  StackTrace:
       at Microsoft.AnalysisServices.AdomdClient.XmlaClient.EndRequest()
       at Microsoft.AnalysisServices.AdomdClient.XmlaClient.SendMessage(Boolean endReceivalIfException, Boolean readSession, Boolean readNamespaceCompatibility)
       at Microsoft.AnalysisServices.AdomdClient.XmlaClient.Discover(String requestType, String requestNamespace, ListDictionary properties, IDictionary restrictions, Boolean sendNamespacesCompatibility)
       at Microsoft.AnalysisServices.AdomdClient.XmlaClient.SupportsProperty(String propName)
       at Microsoft.AnalysisServices.AdomdClient.XmlaClient.Connect(ConnectionInfo connectionInfo, Boolean beginSession)
       at Microsoft.AnalysisServices.AdomdClient.AdomdConnection.XmlaClientProvider.Connect(Boolean toIXMLA)
       at Microsoft.AnalysisServices.AdomdClient.AdomdConnection.XmlaClientProvider.Microsoft.AnalysisServices.AdomdClient.AdomdConnection.IXmlaClientProviderEx.ConnectXmla()
       at Microsoft.AnalysisServices.AdomdClient.AdomdConnection.ConnectToXMLA(Boolean createSession, Boolean isHTTP)
       at Microsoft.AnalysisServices.AdomdClient.AdomdConnection.Open()
       at DataAccess.Repositories.DashboardRepository.<>c__DisplayClass4.<GetTurnover>b__0() in :line 27
       at System.Threading.Tasks.Task.InnerInvoke()
       at System.Threading.Tasks.Task.Execute()
  InnerException: System.Net.WebException
       HResult=-2146233079
       Message=The remote server returned an error: (503) Server Unavailable.
       Source=System
       StackTrace:
            at System.Net.HttpWebRequest.GetResponse()
            at Microsoft.AnalysisServices.AdomdClient.HttpStream.GetResponseStream()
            at Microsoft.AnalysisServices.AdomdClient.HttpStream.GetResponseDataType()
       InnerException: 
0

There are 0 answers