Hello CRM people,
This post is related to my last one: https://community.dynamics.com/crm/f/117/t/231194
I am still trying to execute a report I created in my CRM testenviroment from a Plugin which i trigger via custom action from a button.
My code looks like this:
NetworkCredential Credentials = new NetworkCredential("[USERNAME]", "[PASSWORD]", "[DOMAIN]");
Guid accountId = context.PrimaryEntityId;
byte[] result = null;
ReportExecutionService rs = new ReportExecutionService();
// Credential to connect with CRM
rs.Credentials = Credentials;
// Setting the URL of the Reporting Server
rs.Url = fullURL;
string reportPath = reportNameLong;
// Specify the report path from the reporting server
// Note: To get the report name, report must be published for the external use.
// To do this edit the report from CRM and publish it for external use.
// After publishing it for external use report name will be visible in the reporting server instead of the report id.
string format = "PDF";
string historyID = null;
string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
string encoding;
string mimeType;
string extension;
ReportExecution2005.Warning[] warnings = null;
string[] streamIDs = null;
ExecutionInfo execInfo = new ExecutionInfo();
ExecutionHeader execHeader = new ExecutionHeader();
rs.ExecutionHeaderValue = execHeader;
execInfo = rs.LoadReport(reportPath, historyID);
String SessionId = rs.ExecutionHeaderValue.ExecutionID;
result = rs.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
The problem is that whenever I try to debug the whole thing the Plugin Registration Tool crashes without an error message on the execInfo = rs.LoadReport(reportPath, historyID); so I have no idea what is causing the problem.
I read multiple times that i should pass some credentials to the whole thing like:
var dsc = new ReportExecution2005.DataSourceCredentials
{
DataSourceName = "CRM",
UserName = userName,
Password = passWord
};
but I have no idea how, because ReportExecutionService only accepts ICredentials and not DataSourceCredentials.
I am curently pretty lost here and hope anybody could provide me with an answer how to tackle that whole thing.
Greetings from Germany!
*This post is locked for comments
Had to set the Isolation Mode to "None" on the "Settings" registercard in the "Replay Plug-in Execution" dialog in Plugin Registration Tool...
The whole thing got even weirder. For a time it suddenly worked. While debugging, my Registration Tool didn't crash and i didn't got an error message on ReportExecutionService.Credentials = CredentialCache.DefaultNetworkCredentials; but now again it crashes and gives me an System.Security.Permissions.EnvironmentPermission exeption although I didn't change anything. This is really getting frustrating and you find no real answer when you search for it on google...
Hi thanks for the answer.
Yes this code works when I put it in a normal ConsoleApplication and run it. So it seems that CRM is handling something different but I'm not able to find out at which point I have to change anything.
Hi
Did you run this code outside plugin (eg. Console application)?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156