【发布时间】: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