Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

run crm report in console application

(0) ShareShare
ReportReport
Posted on by 2,409

Hi, I am trying to run crm report in a console application, but it gave me this error "Additional information: One or more data source credentials required to run the report have not been specified." where should I specify the credentials, is not the default credential?

static void Main(string[] args)
        {
            ReportingService2005 rs = new ReportingService2005();
            ReportExecutionService res = new ReportExecutionService();

            rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
            res.Credentials = System.Net.CredentialCache.DefaultCredentials;

            string historyID = null;
            string deviceInfo = null;
            string format = "EXCEL";
            Byte[] results;
            string encoding = String.Empty;
            string mimeType = String.Empty;
            string extension = String.Empty;
            SsrsExecution.Warning[] warnings = null;
            string[] streamIDs = null;

            string fileName = @"c:\samplereport.xls";
   
            string _reportName = @"dev/CustomReports/457a0e9b-970e-e811-a81d-005056b5fefa";
            string _historyID = null;
            bool _forRendering = false;
            SsrsReportService.ParameterValue[] _values = null;
            SsrsReportService.DataSourceCredentials[] _credentials = null;
            SsrsReportService.ReportParameter[] _parameters = null;

            try
            {
                _parameters = rs.GetReportParameters(_reportName, _historyID, _forRendering, _values, _credentials);
                SsrsExecution.ExecutionInfo ei = res.LoadReport(_reportName, historyID);
                SsrsExecution.ParameterValue[] parameters = new SsrsExecution.ParameterValue[1];

                if (_parameters.Length > 0)
                {
                    parameters[0] = new SsrsExecution.ParameterValue();
                    parameters[0].Label = "InvoiceID";
                    parameters[0].Name = "InvoiceID";
                    parameters[0].Value = "66D3BC7B-0926-E811-A81D-005056B5FEFA";
                }
                res.SetExecutionParameters(parameters, "en-us");

                results = res.Render(format, deviceInfo,
                          out extension, out encoding,
                          out mimeType, out warnings, out streamIDs);

                using (FileStream stream = File.OpenWrite(fileName))
                {
                    stream.Write(results, 0, results.Length);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }


*This post is locked for comments

  • sdnd2000 Profile Picture
    sdnd2000 2,409 on at
    RE: run crm report in console application

    Hi, David,

    I am sure it is sql data source, so I do not need set datasroucecredentials, but when I checked the reporting server log, it says "rsCredentialsNotSpecified", and for the datasource, it prompts user name and password to view in report server, I am trying to use the same credentials in the code, but each time it still asks for "rsCredentialsNotSpecified"

  • David Jennaway Profile Picture
    David Jennaway 14,063 on at
    RE: run crm report in console application

    What type of Data Source is used for the report ? If it's the CRM Data Source (rather than a SQL one), then you need to specify the DataSourceCredentials. This will take a systemuserid as the username and the organisationId as the password. The code would be something like this:

    DataSourceCredentials credentials = new DataSourceCredentials();
    credentials.DataSourceName = "MSCRM";   //this is the default name, but check in Report Manager
    credentials.UserName = userId.ToString("B");
    credentials.Password = orgId.ToString("B");
    SsrsReportService.DataSourceCredentials[] _credentials = new SsrsReportService.DataSourceCredentials[]{credentials};


  • sdnd2000 Profile Picture
    sdnd2000 2,409 on at
    RE: run crm report in console application

    Hi, I tried "new NetworkCredential(UserName, PassWord, Domain)", but I still get the same error ("One or more data source credentials required to run the report have not been specified"). When I view the report, there is no issue with my credentials. 

  • sdnd2000 Profile Picture
    sdnd2000 2,409 on at
    RE: run crm report in console application

    Hi, Ravi, I have to provide user name and password when browsering report, also, I do not see the credentials as below:

    2018_2D00_03_2D00_13_5F00_0841.png

  • Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: run crm report in console application

    Hi Amit,

    this will not work in CRM online, only on premises.

  • RE: run crm report in console application

    Hi Ravi,

    Will it work for any report in the online CRM also?

    Do we need to take care any thing special in case of online CRM?

    Thanks

    Amit Kumar Rath

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 Moderator on at
    RE: run crm report in console application

    Hi,

    Could you please confirm if you are able to browse the report in browser? If yes, are you providing any credential there.

    Normaly default credential will pass the logged in user (user who is logged in to the system). If you want to pass some other credential, you can try

    -----------

    new NetworkCredential(UserName, PassWord);

    -----------------

    stackoverflow.com/.../how-to-pass-credentials-to-httpwebrequest-for-accessing-sharepoint-library

    Hope this helps.

  • sdnd2000 Profile Picture
    sdnd2000 2,409 on at
    RE: run crm report in console application

    Hi, it seems like it didn't get my credentials, but how to pass that?  I do have specified  "res.Credentials = System.Net.CredentialCache.DefaultCredentials;"

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 Moderator on at
    RE: run crm report in console application

    Hi,

    Below is the code I have used to render the report as PDF and save it to the disk.

    =============

    public void SaveReportToPDF()

           {

               string URL = "server-nb-09/ReportServer_sqlexpress2016;rs:Format=PDF";

               System.Net.HttpWebRequest Req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(URL);

               Req.Credentials = System.Net.CredentialCache.DefaultCredentials;

               Req.Method = "GET";

               //Specify the path for saving.

               string path = @"C:\Ravi\firstReport1.pdf";

               System.Net.WebResponse objResponse = Req.GetResponse();

               System.IO.Stream stream = objResponse.GetResponseStream();

               MemoryStream ms = new MemoryStream();

               stream.CopyTo(ms);

               byte[] data = ms.ToArray();

               File.WriteAllBytes(path, data);

           }

    ======================

    Hope this helps-

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: run crm report in console application

    Hi,

    you should use the credential that can connect and call the reporting web service.

    In you code should be under

    res.Credentials = System.Net.CredentialCache.DefaultCredentials;

    The below is my code that using in my own environment, I am using admin to call the reporting web service.

    2768.30.png

    2768.30.png

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,430 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans