【问题标题】:Pass Windows Identity to SSRS Report Custom Data Source将 Windows 标识传递给 SSRS 报告自定义数据源
【发布时间】: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


    【解决方案1】:

    我发现这是在寻找关于类似情况的不同答案。不过,在我的情况下,我将 rptViewer.ServerReport.ReportServerCredentials 设置为有权访问报告的 Windows 帐户。没有它,我作为连接字符串提供的内容没有任何区别,应用程序甚至无法访问报告。我看到这是旧的,但这可能是你的问题吗?我只是想知道如果使用参数将连接字符串传递给报告,连接字符串是否更有风险,以及是否有比在 web.config 中存储 AD 帐户和密码更好的选择,以便ReportViewer 以访问报告。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多