【问题标题】:Credentials - Microsoft reporting library凭据 - Microsoft 报告库
【发布时间】:2017-12-01 17:40:31
【问题描述】:

我对 Microsoft.Reporting 库有疑问。我需要访问 SQL 报告服务,并且我有报告名称、服务器地址以及用户名和密码。首先,我需要获取一份特定报告所需的所有参数。

这是我目前的实现:

using System;
using System.Collections.Generic;
using Microsoft.Reporting.WinForms;

namespace ConsoleApp1
{
    class Program
    {
        static IEnumerable<DataSourceCredentials> CredentialsEnumerable()
        {
            var credentials = new DataSourceCredentials
            {
                Name = @"domain\account",
                Password = @"password"
            };
            yield return credentials;
        }
        static void Main(string[] args)
        {
            var credentials = new DataSourceCredentials
            {
                Name = @"domain\account",
                Password = @"password"
            };

            var report = new ReportViewer
            {
                ProcessingMode = ProcessingMode.Remote
            };
            report.ServerReport.ReportPath = @"/Archiv/Daily sales";
            report.ServerReport.ReportServerUrl = new Uri(@"http://serverIPaddress/reportserver");
            report.ServerReport.SetDataSourceCredentials(credentials);
            foreach (var param in report.ServerReport.GetParameters())
            {
                Console.WriteLine(param.ToString());
            }
            Console.ReadLine();
        }
    }
}

但我的代码有问题,主要是:

report.ServerReport.SetDataSourceCredentials(credentials);

我收到错误消息,无法从 Microsoft.Reporting.WinForms.DataSourceCredentials 转移到 System.Collections.Generic.IEnumerable 我已经尝试使用变量“凭据”并创建了 IEnumerable 类,但它不起作用。

您能否建议我的代码有什么问题?如何修复它并为报告服务器提供凭据?如果没有凭据,我会收到错误“未授权”

提前谢谢你

【问题讨论】:

  • 您将单个元素传递给 SetDataSourceCredentials。它期望收到一个数组。您是否尝试使用 report.ServerReport.SetDataSourceCredentials(Program.CredentialsEnumerable()); 或简单地使用 report.ServerReport.SetDataSourceCredentials(new DataSourceCredentials[] { credentials});
  • 是的,我试过了,没用。我可以使用 webbrowser 进行连接,但我的程序仍然报错“HTTP 401:Unauthorized”

标签: c# reporting-services


【解决方案1】:

问题已解决 - 凭据参数错误。 而不是:

report.ServerReport.SetDataSourceCredentials(credentials);

我用过

report.ServerReport.ReportServerCredentials.NetworkCredentials = credentials;

它的工作原理!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多