title: How to test connection to a data source in SSAS using C#
body: <p>I have a database in Analysis Services on a remote server.  This contains a data source for another database located on another remote server.</p>
  
  <p>I am trying to write a connectivity test using C# which will check the database connection between the two databases. </p>
  
  <p><del>I have been unable to do this using ADOMD.NET.  I'm currently looking at using SMO to do this but I haven't had any luck so far.</del></p>
  
  <p><del>I would greatly appreciate any advice or suggestions.</del></p>
  
  <p><b>Update:</b><br> 
  After further research, I have come up with the below test (Please note that I intend to add more try..catch blocks and Assertions later).  </p>
  
  <p>Also, this uses <em>C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.AnalysisServices.DLL</em> to access the Server, Database and 
  DataSource classes.</p>
  
  <pre><code>class ConnectivityTests
  {
      // Variables
      String serverName = "";
      String databaseName = "";
      String dataSourceName = "";
  
      [Test]
      public void TestDataSourceConnection()
      {
          // Creates an instance of the Server
          Server server = new Server();
          server.Connect(serverName);
  
          // Gets the Database from the Server
          Database database = server.Databases[databaseName];
  
          // Get the DataSource from the Database
          DataSource dataSource = database.DataSources.FindByName(dataSourceName);
  
          // Attempt to open a connection to the dataSource.  Fail test if unsuccessful
          OleDbConnection connection = new OleDbConnection(dataSource.ConnectionString);
          try
          {
              connection.Open();
          }
          catch (OleDbException e)
          {
              Assert.Fail(e.ToString());
          }
          finally
          {
              connection.Close();
          }
  
      }
  </code></pre>
  
  <p>I believe that this test is sufficient for my testing (Once I've added some more try..catch blocks and Assertions).  If the test passes, it means there are no connectivity issues between my machine and both servers, which implies that there shouldn't be any connectivity issues between the servers.</p>
  
  <p>However, I have been unable to work out how to test the connection between the two servers directly and I am interested if anyone knows a way of doing this.</p>