1
     public static void connect()
     {   
        try
        {
            string connectionStringStaging = @"Data Source=<server_name>;Catalog=<catalog_name>;User ID=<user_name>;Password=<my_password>";
            string commandText = @"SELECT NON EMPTY { [Measures].[# Opptys moved to Committed] } ON COLUMNS FROM [Model] 
                                    CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS";
            AdomdConnection connection = new AdomdConnection(connectionStringStaging);
            connection.Open();
            AdomdCommand cmd = new AdomdCommand(commandText);
            cmd.Connection = connection;
            using (var reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    Console.WriteLine(reader[0]);
                }
            }
        }
        catch (AdomdConnectionException ex)
        {
            Console.WriteLine("Error : " + ex.ToString());
        }
     }

I am using the above code to connect to server and then I am further running MDX queries using this.The problem is the error I am getting - "The connection string is not valid" at line

connection.open(); 

Are the settings name incorrect which I am using in my connection string?Can someone help me figure out what is wrong in my connection string ?

The stack trace is as follows: enter image description here

Tarun Talreja
  • 163
  • 1
  • 12

2 Answers2

0

Please consult the following documentation from Microsoft: https://msdn.microsoft.com/en-us/library/microsoft.analysisservices.adomdclient.adomdconnection.connectionstring.aspx

You can also find some examples of connection strings here: https://www.connectionstrings.com/adomd-net/

Hope this will help you sort the problem.

Bogdan Anghel
  • 184
  • 3
  • 12
  • I have already seen the same document but nothing helps, I am not able to find what is wrong in my connection string – Tarun Talreja Jul 03 '17 at 11:24
  • Please enclose the code in a try / catch block and post the full stack trace here so I can better understand the problem. – Bogdan Anghel Jul 03 '17 at 11:59
  • From what I can see in the stack trace the `connection.Open()` call needs to parse a port number, that is not provided in the connection string. Your problem may be in the string. Below are the examples from the Microsoft documentation: 1.Data source=AW-SRV01 for the default instance and port (TCP 2383). 2.Data source=AW-SRV01$Finance:8081 for a named instance ($Finance) and fixed port. 3. Data source=AW-SRV01.corp.Adventure-Works.com for a fully qualified domain name, assuming the default instance and port. 4 Data source=172.16.254.1 for an IP address of the server. – Bogdan Anghel Jul 03 '17 at 12:59
  • My Data Source is `Data Source=asazure://aspaaseastus2.asazure.windows.net/dwraasstaging` – Tarun Talreja Jul 03 '17 at 13:09
  • The link you gave didn't work but the answer below it fixed my issue. – Tarun Talreja Jul 04 '17 at 04:35
0

I found my answer here. The unofficial package worked just fine . So I installed the reference Unofficial.Microsoft.AnalysisServices.AdomdClient and so the problem was not in the connection string but in the package.

Tarun Talreja
  • 163
  • 1
  • 12