如何使用C#测试SSAS中与数据源的连接

我在远程服务器上的Analysis Services中有一个数据库。 它包含位于另一个远程服务器上的另一个数据库的数据源。

我正在尝试使用C#编写连接测试,它将检查两个数据库之间的数据库连接。

我无法使用ADOMD.NET执行此操作。 我目前正在考虑使用SMO来做到这一点,但到目前为止我还没有运气。

我非常感谢任何建议或意见。

更新:
经过进一步研究,我提出了以下测试(请注意,我打算稍后添加更多try..catch块和断言)。

此外,它使用C:\ Program Files \ Microsoft SQL Server \ 100 \ SDK \ Assemblies \ Microsoft.AnalysisServices.DLL来访问Server,Database和DataSource类。

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(); } } 

我相信这个测试足以进行我的测试(一旦我添加了一些try..catch块和断言)。 如果测试通过,则表示我的计算机与两台服务器之间没有连接问题,这意味着服务器之间不应存在任何连接问题。

但是,我一直无法确定如何直接测试两个服务器之间的连接,如果有人知道这样做的话我感兴趣。

我在进行此连接测试时遇到的最佳解决方案如下:请注意,这需要添加Microsoft.AnalysisServices.DLL作为参考。

 class ConnectivityTests { // Variables String serverName = ""; String databaseName = ""; String dataSourceName = ""; [Test] public void TestDataSourceConnection() { try { // 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); connection.Open(); } catch (Exception e) { Assert.Fail(e.ToString()); } finally { connection.Close(); } } }