简体   繁体   English

如何从 SSRS 报告中获取数据源信息,使用 .NET

[英]How to get the data source information from a SSRS report, using .NET

I am currently making an ASP.Net and C# page, which is a front end for some reports.我目前正在制作一个 ASP.Net 和 C# 页面,这是一些报告的前端。

I also want to run some queries, from the same data source as the reports (each report uses just 1 data source).我还想从与报告相同的数据源运行一些查询(每个报告仅使用 1 个数据源)。

Is it possible to extract the data source connection information from a report, using either ReportingService2005 or ReportExecutionService members, so that it can be reused in an SqlConnection?是否可以使用 ReportingService2005 或 ReportExecutionService 成员从报表中提取数据源连接信息,以便在 SqlConnection 中重用?

You can use the ReportingService2005 API to get the datasource used by a particular report.您可以使用 ReportingService2005 API 获取特定报告使用的数据源。

You need the full path of the report (which I assume you have), and then use it to query the reporting service for its data source ( API ).您需要报告的完整路径(我假设您有),然后使用它来查询报告服务的数据源( API )。

// rs = ReportingService2005 that you need to set up.

DataSource ds;
DataSources dataSources = rs.GetItemDataSources(item);

// item is a string containing the full path to the report.

dataSources = rs.GetItemDataSources(item);
ds = dataSources[0];

The ds in the code above is either a DataSourceDefinition or a DataSourceReference .上面代码中的 ds 是DataSourceDefinitionDataSourceReference If it's a definition you can just cast it into that type and then get the connection string using the following code.如果它是一个定义,您可以将其转换为该类型,然后使用以下代码获取连接字符串。

DataSourceDefinition dsd = ds as DataSourceDefinition();
if(dsd == null)
    throw new Exception();

String connectionString = dsd.ConnectString;

If it's a datasourcereference you need to check out the API .如果它是数据源引用,您需要查看API

Hopefully this is of some help.希望这会有所帮助。 It will list all the properties, but specifically it pulls out the connection string:它将列出所有属性,但特别是它会拉出连接字符串:

using System;
using GetPropertiesSample.ReportService2010; //This is the WebService Proxy
using System.Diagnostics;
using System.Reflection;
using System.Web.Services.Protocols;
using System.IO;

namespace GetPropertiesSample
{
class Program
{
    static void Main(string[] args)
    {
        Get_Properties_of_DataSource_given_The_Path_and_Name_of_the_Report();
    }

    private static void Get_Properties_of_DataSource_given_The_Path_and_Name_of_the_Report()
    {
        try
        {

            // Create a Web service proxy object and set credentials
            ReportingService2010 rs = new ReportingService2010();
            rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
            string reportPathAndName = "/0_Contacts/209_Employee_Telephone_List_Printable";

            DataSource[] dataSources = rs.GetItemDataSources(reportPathAndName);

            DataSource ds = dataSources[0];
            string dsName = ds.Name;
            Debug.Print("----------------------------------------------------");
            Debug.Print("Data Source Name: " + dsName);
            Debug.Print("----------------------------------------------------");
            DataSourceDefinition dsd = (DataSourceDefinition)ds.Item;
            if (dsd != null)
            {
                //Here is one property
                string connectionString = dsd.ConnectString;  // <======   HERE is the Connection Strin
                //Use Reflection to get all the properties :    using System.Reflection;
                var typeDSD = typeof(DataSourceDefinition);
                var properties = typeDSD.GetProperties();
                foreach (PropertyInfo p in properties)
                {
                    Debug.Print("----------------------------------------------------");
                    Debug.Print(p.Name + ": " + p.GetValue(dsd, null));
                }
            }

        }
        catch (SoapException e)
        {
            Debug.Print("==============================");
            Debug.Print(e.Detail.OuterXml);
            Debug.Print("==============================");
        }
        catch (Exception e)
        {
            Debug.Print("==============================");
            Debug.Print(e.Message);
            Debug.Print(e.InnerException.ToString());
            Debug.Print(e.ToString());
            Debug.Print("==============================");
        }
    }
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何动态更改SSRS报告数据源的连接类型 - How to change connection type of SSRS report Data source dynamically 从SSRS报告中获取参数 - Get Parameters from SSRS Report 是否可以以及如何针对SQL Server中本地报告服务的在线Dynamics CRM数据源运行SSRS报告? - Is it possible and how to run an SSRS report against an online dynamics CRM data source from a local reporting service in SQL Server? 将SharePoint 2013与SSRS报告数据集成,或使用TimerJob将数据从SSRS提取到SharePoint中 - Integrating SharePoint 2013 with SSRS report Data or Extracting Data from SSRS into SharePoint using a TimerJob 在服务器端以编程方式更改报告的SSRS数据源 - Change SSRS data source of report programmatically in server side 如何使用报告查看器从 asp 网页打开 ssrs 报告 - how to open ssrs report from asp web page using report viewer 从IIS运行时,SSRS(Sql Server 2016)报告错误为“无法创建与数据源DSTEST的连接”。 (rsErrorOpeningConnection)&#39; - SSRS(Sql Server 2016) Report error when running from IIS is 'Cannot create a connection to data source 'DSTEST'. (rsErrorOpeningConnection)' 如何使用代码(xml)生成SSRS报告? - How to generate SSRS report using the code (xml)? 使用C#代码从报表服务器下载SSRS报表 - Downloading SSRS report from report server using C# code 如何使用c#在asp.net页面中部署或显示SSRS报告? - How to deploy or show a SSRS report in asp.net page using c#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM