簡體   English   中英

憑據-Microsoft報告庫

[英]Credentials - Microsoft reporting library

我對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,我已經嘗試過使用變量“ credentials”並創建IEnumerable類,但是它無法正常工作。

您能建議我的代碼有什么問題嗎? 如何修復它並為報告服務器提供憑據? 沒有憑據,我會收到錯誤“未授權”

先感謝您

問題已解決-憑證參數錯誤。 代替 :

report.ServerReport.SetDataSourceCredentials(credentials);

我用了

report.ServerReport.ReportServerCredentials.NetworkCredentials = credentials;

而且有效!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM