c# – Unable to display result from Microsoft Analysis Services into textbox

0
7

Hello stackoverflow community,
I have been entirely perplexed by what looks to be a very simple c# program to access SSAS server in my winforms program. My winform program is meant to return a predicted value based on the input added to a mining model set up in SSAS. When I hit the predict button, nothing is returned. Could someone please help me figure out what I am doing wrong?

My connection string to the server is set up as follows;

string analysisServer = "Provider=MSOLAP.8;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=HDPurchasingPredictiveAnalysis;Data Source=TJ-PC;Impersonation Level=Impersonate;Location=TJ-PC;Update Isolation Level=2";

`

private void buttonPredict_Click(object sender, EventArgs e)
        {

        if (radioButtonANN.Checked.Equals(false) || radioButtonClustering.Checked.Equals(false)|| radioButtonLR.Checked.Equals(false))
        {
            MessageBox.Show("Please select a data mining algorithm in order to carry out analysis ");
        }
        else if(radioButtonANN.Checked.Equals(true))
        {

            string dmxQuery = @"SELECT [DrugPricingCostNN].[Drug Cost_] From [DrugPricingCostNN] NATURAL PREDICTION JOIN (SELECT '" + dependentVariable.Text + @"'AS [ASP 2016]) AS t";
            try
            {
                //Open a connection to the analysis services server
                AdomdConnection connection = new AdomdConnection(analysisServer);
                connection.Open();

                AdomdCommand command = new AdomdCommand(dmxQuery, connection);
                AdomdParameter param = command.CreateParameter();
                param.Direction = System.Data.ParameterDirection.Input;
                param.ParameterName = "ASP 2016";
                param.Value = dependentVariable.Text;
                command.Parameters.Add(param);
                AdomdDataReader reader = command.ExecuteReader();
                reader.Read();

                //Init stringBuilder
                StringBuilder stringBuilder = new StringBuilder();

                for (int i = 0; i < reader.FieldCount; i++)
                {
                    stringBuilder.Append(reader.GetName(i) + "t");
                }
                stringBuilder.Append("rn--------------------------------------------rn");
                //Important before accessing any data, call the .Read method
                while (reader.Read())
                {
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        stringBuilder.Append(reader.GetValue(i).ToString() + "t");
                    }
                    stringBuilder.Append("rn");
                }
                //Return the predicted value and display it in the text box
                predictedValue.Text = stringBuilder.ToString();
                Console.Write(stringBuilder.ToString());
                reader.Close();
            }
            catch (Exception)
            {

                throw;
            }

`

Working in Visual Studio 2017 Developer Edition, SSAS v2017, .NET Framework 4.6.1.

Any help to address what I could be missing out on will help a great deal.

Thank you.

LEAVE A REPLY

Please enter your comment!
Please enter your name here