如何使用 C# 在 SSAS 中测试与数据源的连接 [英] How to test connection to a data source in SSAS using C#

查看:31
本文介绍了如何使用 C# 在 SSAS 中测试与数据源的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

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

如果您有任何建议或建议,我将不胜感激.

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

Update:
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).

此外,这使用 C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.AnalysisServices.DLL 来访问服务器、数据库和数据源类.

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

    }

我相信这个测试对于我的测试来说已经足够了(一旦我添加了更多的 try..catch 块和断言).如果测试通过,则意味着我的机器和两台服务器之间没有连接问题,这意味着服务器之间不应该有任何连接问题.

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.

但是,我一直无法弄清楚如何直接测试两台服务器之间的连接,如果有人知道这样做的方法,我很感兴趣.

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.

推荐答案

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

The best solution I have come across to doing this connectivity test is below: Please note that this requires the Microsoft.AnalysisServices.DLL to be added as a reference.

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

     }
}

这篇关于如何使用 C# 在 SSAS 中测试与数据源的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆