【发布时间】:2017-09-13 06:43:50
【问题描述】:
我是 SSRS 报告领域的新手,在尝试连接到我的数据源时遇到了一些问题。
我创建了一个具有以下属性的新数据源
- 使用我的报告中嵌入的连接
- 连接类型:Microsoft SQL Server
- 连接字符串:[@ConnectionString],其中@ConnectionString 是我的报告参数的名称。
在凭据选项卡中
- 提示输入凭据(未选中“用作 Windows 凭据”复选框)
我正在使用此数据源在我的报表的下拉控件中预填充数据库中的可用值。 现在,场景是我要将连接字符串从我的 aspx 页面传递到 SSRS 报告查看器。
以下代码摘录:
this.rptViewer.ProcessingMode = ProcessingMode.Remote;
this.rptViewer.ServerReport.ReportServerUrl = new Uri(reportServerUrl);//https
this.rptViewer.ServerReport.ReportPath = reportPath;
// this can have either UserName & Password specified or have IntegratedSecurity=SSPI
connStrBuildr.ConnectionString = connStr;
ReportParameter reportParameter = new ReportParameter("ConnectionString", connStrBuildr.ConnectionString, false);
this.rptViewer.ShowCredentialPrompts = false;
this.rptViewer.ServerReport.SetParameters(reportParameter);
if (!connStrBuildr.IntegratedSecurity) { // for SQL Auth
this.rptViewer.ServerReport.SetDataSourceCredentials(new List<DataSourceCredentials>() {
new DataSourceCredentials() {
Name = "Custom_DataSource",
UserId = connStrBuildr.UserID,
Password = connStrBuildr.Password } });
}
else // for Windows Auth
{
// Created a new class as per some suggestion on internet, to connect to ReportServer which inturn will pass window identity to SQL Server,
// but even this didn't work - had no way to exact password . MIND BLOWING STUFF !!
//rptViewer.ServerReport.ReportServerCredentials = new CustomReportCredential(username,password,domain)
}
this.rptViewer.ServerReport.Refresh();
我的要求是 如果我的连接字符串指定了用户名和密码,那么这些应该用于连接 SQL (Custom_DataSource)。
如果 IntegratedSecurity=SSPI 被指定,它应该使用 Windows 身份验证来连接 SQL (Custom_DataSource)。
我尝试过创建派生类
CustomReportCredential:Microsoft.Reporting.WebForms.IReportServerCredentials
但即使这样也没有成功。修改 web.config 以保持模拟(true/false),以及许多类似的。他们都没有成功。
目前的情景: 如果我将报告更改为使用 Windows 集成安全性,我所有启用 Windows 身份验证的连接字符串都可以正常运行,但对于指定了用户名和密码的连接字符串会失败。
反之亦然,如果我将报告更改为使用凭据提示(未选中“用作 Windows 凭据”复选框)。
预期:
- 如何允许两种方法 (Windows/SQL) 连接到 DataSource?
这可能是一个微不足道的场景,但我无法找到合适的解决方案。
任何帮助或指示将不胜感激。谢谢。
【问题讨论】:
标签: asp.net reporting-services datasource reportviewer ssrs-2012