How to check data source connection in SSAS using C #

I have a database in Analysis Services on a remote server. It contains a data source for another database located on another remote server.

I am trying to write a connection test using C # that will check the database connection between two databases.

I could not do this using ADOMD.NET. I am currently looking at using SMO, but I'm not so lucky.

I would really appreciate any advice or suggestions.

Update:
After further research, I came up with a test below (note that I intend to add a few more try..catch and Assertions blocks later).

In addition, it uses C: \ Program Files \ Microsoft SQL Server \ 100 \ SDK \ Assemblies \ Microsoft.AnalysisServices.DLL to access the Server, Database and DataSource Classes.

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

I believe that this test is sufficient for my testing (as soon as I added a few more try..catch and Assertions blocks). If the test passes, it means that there are no connection problems between my machine and both servers, which implies that there should be no connection problems between the servers.

However, I was not able to figure out how to directly check the connection between the two servers, and I am wondering if anyone knows about this.

+4
source share
1 answer

The best solution that I encountered while performing this connection test is as follows: Please note: for this you need to add Microsoft.AnalysisServices.DLL as a link.

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

Source: https://habr.com/ru/post/1435890/


All Articles