How to debug a server-side (.rdl) report that does not work in my application? - ssrs-2008

I have a SQL Server Report Server (SSRS) that hosts a bunch of reports. When I click on the provided URL, I can navigate to the report, drilling down the path, and I can successfully run the report by passing it the required parameters. The Stored Procedures used by the report are hosted in a database that uses Windows Authentication.
However, when I try to call the same report from my application, I cannot see anything.
Here is the code I use. Upon clicking on a button, I execute this code:
var reportViewer = new ReportViewer();
// Set Processing Mode
reportViewer.ProcessingMode = ProcessingMode.Remote;
// Set report server and report path
reportViewer.ServerReport.ReportServerUrl = new Uri("http://MySsrsServer/reportserver");
reportViewer.ServerReport.ReportPath = "/Reports/MyReport";
// set the credentials
reportViewer.ServerReport.ReportServerCredentials.ImpersonationUser = WindowsIdentity.GetCurrent();
// create report parameters and set them in the report
var param1 = new ReportParameter("First_Param", "Some string");
var param2 = new ReportParameter("Second_Param", "Some other string");
reportViewer.ServerReport.SetParameters(new ReportParameter[] { param1, param2 });
using (var reportForm = new ReportForm(reportViewer))
{
reportForm.ShowDialog();
}
The ReportForm is just a regular Form that has a member of type ReportViewer. In the class constructor I assign the member:
public ReportForm(ReportViewer reportViewer)
{
InitializeComponent();
try
{
this.reportViewer = reportViewer;
reportViewer.SetDisplayMode(DisplayMode.PrintLayout);
reportViewer.Dock = DockStyle.Fill;
reportViewer.ZoomMode = ZoomMode.Percent;
reportViewer.ZoomPercent = 100;
reportViewer.RefreshReport();
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
}
As I said, I can see the report being correctly executed from Server, but not from my application. The content of the ReportForm is empty, but I do not get any exceptions being thrown.
Any idea what is it I am doing wrong?
TIA,
E

Turns out that constructing the ReportViewer object outside the form where the report is to be displayed and then passing it inside the constructor of the form in order to assign it to the inner ReportViewer object is not a good idea. I don't know what's happening behind the scene, perhaps some bindings between the ReportViewr instance and the GUI control that is to show the report are broken.

Related

Sparx EA diagram update with API fails with error No such diagram found having diagram GUID

I have a C# script performing create/update operations to EA diagrams. It's working good with EA 15. But when I run it with EA 16, it fails with the error - "No such diagram found having diagram GUID:"
Here is the details of example user case.
Script is connecting with one user to EA and creating diagram. Now next time script runs and connects with another user to EA and try to update earlier created diagram.
Based on the new version 16 document, I know that it's required to be reloaded. When I try to update the same diagram from the EA UI, I get the error and it asked to reload that diagram. After reload I am able to update the diagram from the UI.
Same thing I tried from the code to reload the diagram (using Repository.ReloadDiagram (currentDiagram.DiagramID);) and then update (diagram.Update()), but still I am getting same error.
Also tried to login with 2nd user in UI and set the reload changed diagram to true from Design->Diagram->Options->auto reload changed diagram. This also does not reload the diagram and shows pop up to reload before updating entity.
Update:
Here is the code snippet that I am using. It gives error on second diagram.Update() i.e. after connecting to user2 and trying to update diagram from his connection with following error "No such diagram found having diagram GUID: "
{
//connect to user1
EAConnection connection = new EAConnection();
connection.EARepository = new Repository();
connection.EARepository.SuppressSecurityDialog = true;
connection.EARepository.SuppressEADialogs = true;
bool isOpened = connection.EARepository.OpenFile2("path", "user1", "password");
//update diagram with user1
diagram = repository.GetDiagramByGuid(guid);
repository.ReloadDiagram(diagram.DiagramID); //reload diagram object
//update attribute values
diagram.Name = "xyz";
diagram.Update();
//connect to user2
EAConnection connection = new EAConnection();
connection.EARepository = new Repository();
connection.EARepository.SuppressSecurityDialog = true;
connection.EARepository.SuppressEADialogs = true;
bool isOpened = connection.EARepository.OpenFile2("path", "user2", "password");
//update diagram with user2
diagram = repository.GetDiagramByGuid(guid);
repository.ReloadDiagram(diagram.DiagramID); //reload diagram object
diagram.Name = "abc";
diagram.Update();
}
It looks like you have not posted the part of the code where the actual problem is.
This code is tested on version 16.1 (64 bit) and works without any problems.
namespace EA_console_app
{
internal class Program
{
static void Main(string[] args)
{
// connect to user1
var path = #"C:\temp\test project.qea";
var repository = new EA.Repository();
repository.SuppressSecurityDialog = true;
repository.SuppressEADialogs = true;
var isOpened = repository.OpenFile2(path, "user1", "user1");
var guid = "{9585B09C-28C5-485b-AF25-79F1D70EAA18}";
//update diagram with user1
var diagram = repository.GetDiagramByGuid(guid);
//repository.ReloadDiagram(diagram.DiagramID);
diagram.name = "xyz";
var user1Update = diagram.Update();
//connect to user2
var repository2 = new EA.Repository();
repository2.SuppressSecurityDialog = true;
repository2.SuppressEADialogs = true;
isOpened = repository2.OpenFile2(path, "user2", "user2");
//update diagram with user1
diagram = repository.GetDiagramByGuid(guid);
//repository.ReloadDiagram(diagram.DiagramID);
diagram.name = "abc";
var user2Update = diagram.Update();
}
}
}
You might want to check the permissions of your user1 and user2. If they don't have permission to update diagrams, the Update() operation will return false.
What I'm guessing is that you actually try to create a diagram as well (as indicated in the text, but not present in the code), but that your user1 doesn't have the permission to create diagrams. That means that the Update() for user1 fails, and doesn't create the diagram after all. That means the GetDiagramByGuid for user2 will fail.
In that case you would get error like: System.Runtime.InteropServices.COMException: 'Can't find matching ID' instead of the error you mentioned: No such diagram found having diagram GUID:
The method repository.ReloadDiagram does not do what you think it does. It will refresh the visual rendering of the diagram in the GUI, but it will not affect your diagram object in any way. Since you are not even showing the GUI this is completely useless in this context.
You are using the same GUID on two different repositories. That does not make any sense since GUIDs are designed to be different everywhere. So no wonder you don't find the diagram with the GUID from the first repo in the second.
Assuming "path" is different in both Open statements since opening the same repo as two instances would be nonsense as well.

Plug-In that Converted Note entity pre-existing attachment XML file into new .MMP file

strong text [Plugin error at Note entity][1]
[1]: http://i.stack.imgur.com/hRIi9.png
Hi,Anyone resolved my issue i got a Plug-in error which i worked at Update of "Note" entity.Basically i want a Plugin which converted pre-exiting Note attachment XML file into new .MMP extension file with the same name.
I have done following procedure firstly i created a "Converter_Code.cs" dll which contains Convert() method that converted XML file to .MMP file here is the constructor of the class.
public Converter(string xml, string defaultMapFileName, bool isForWeb)
{
Xml = xml;
DefaultMapFileName = defaultMapFileName;
Result = Environment.NewLine;
IsForWeb = isForWeb;
IsMapConverted = false;
ResultFolder = CreateResultFolder(MmcGlobal.ResultFolder);
}
In ConvertPlugin.cs Plug-in class firstly i retrieved Note entity attachment XML file in a string using following method in
IPluginExecutionContext context =(IPluginExecutionContext)serviceProvider.
GetService (typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory= (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService
(context.UserId);
if (context.InputParameters.Contains("Target")
&& context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parameters.
Entity entity = (Entity)context.InputParameters["Target"];
var annotationid = entity.GetAttributeValue<Guid>("annotationid");
if (entity.LogicalName != "annotation")
{
return;
}
else
{
try
{
//retrieve annotation file
QueryExpression Notes = new QueryExpression { EntityName ="annotation"
,ColumnSet = new ColumnSet("filename", "subject", "annotationid",
"documentbody") };
Notes.Criteria.AddCondition("annotationid", ConditionOperator.Equal,
annotationid);
EntityCollection NotesRetrieve = service.RetrieveMultiple(Notes);
if (NotesRetrieve != null && NotesRetrieve.Entities.Count > 0)
{
{
//converting document body content to bytes
byte[] fill = Convert.FromBase64String(NotesRetrieve.Entities[0]
.Attributes["documentbody"].ToString());
//Converting to String
string content = System.Text.Encoding.UTF8.GetString(fill);
Converter objConverter = new Converter(content, "TestMap", true);
objConverter.Convert();
}
}
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("something is going wrong");
}
}
}
}
and than A string is passed to "Converter" constructor as a parameter.
finally i merged all dll using ILMerge following method:
ilmerge /out:NewConvertPlugin.dll ConvertPlugin.dll Converter_Code.dll
and NewConvertPlugin is registered successfully but while its working its generate following error:
Unexpected exception from plug-in (Execute): ConverterPlugin.Class1: System.Security.SecurityException: That assembly does not allow partially trusted callers.
i also debug the plugin using Error-log but its not worked so i could not get a reason whats going wrong.
The error is caused by the library you merged inside your plugin.
First of all you are using CRM Online (from your screenshot) and with CRM Online you can use only register plugins inside sandbox.
Sandbox means that your plugins are limited and they run in a partial-trust environment.
You merged an external library that requires full-trust permissions, so your plugin can't work and this is the reason of your error.
Because you are in CRM Online, or you find another library (the Converter) that requires only partial-trust, hoping that the merge process will work, or you include (if you have it) the source code of the converter library directly inside your plugin.

Write CRM Plugin that Fires when a Field is updated

We're on CRM 2013 on-premise. I'm writing a plugin that fires when a field on Quote entity is updated.
So I registered my plugin on 'Update' message. Then the event is 'Post-operation'. (I tried Pre-operation but still no luck)
Basically the goal is when the field is updated, create a new entity 'ContractShell' and then create relationship between the Quote and the newly created 'ContractShell'.
However my problem is when the field is updated, my plugin never seems to fire. I just simply put a InvalidPluginExecutionException in my code, but for some reason it never fires.... Any ideas? Thanks.
Here's a screenshot of my plugin step:
Here's my code:
var trace = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
// The InputParameters collection contains all the data passed in the message request.
var targetEntity = context.GetParameterCollection<Entity>(context.InputParameters, "Target");
if (targetEntity == null)
throw new InvalidPluginExecutionException(OperationStatus.Failed, "Target Entity cannot be null");
if (!context.OutputParameters.Contains("id"))
return;
Guid QuoteId = (Guid)targetEntity.Attributes["quoteid"];
var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var service = serviceFactory.CreateOrganizationService(context.UserId);
var contractShellEntity = new Entity();
contractShellEntity = new Entity("new_);
//assign the portfolio
if (targetEntity.Attributes.Contains(Schema.Quote.Portfolio))
{
var quotePortfolio = (EntityReference)targetEntity.Attributes[Schema.Quote.Portfolio];
contractShellEntity[Schema.new_ContractShell.PortfolioName] = new EntityReference(quotePortfolio.LogicalName, quotePortfolio.Id);
}
var contractShellId = service.Create(contractShellEntity);
throw new InvalidPluginExecutionException(OperationStatus.Failed, "I created New Contract Shell");
//Creating relationship between Contract Shell and the newly created Accounts
var quoteContractReferenceCollection = new EntityReferenceCollection();
var quoteContractRelatedEntity = new EntityReference
{
Id = contractShellId,
LogicalName = contractShellEntity.LogicalName
};
quoteContractReferenceCollection.Add(quoteContractRelatedEntity);
var quoteContractReferenceCollectionRelRelationship = new Relationship
{
SchemaName = Schema.new_ContractShell.ContractQuoteRelationship
};
service.Associate("quote", QuoteId, quoteContractReferenceCollectionRelRelationship, quoteContractReferenceCollection);
You need to register not only the plugin but an SDKMessageProcessingStep. Also, you have to implement the Execute method in your plugin to be able to register it, so either you're missing code in your snippet, or your code is the problem.
Also, your InvalidPluginExecutionException is nested after a number of checks. Theres a good chance you don't have any output parameters if you don't know how to register a plugin, so your code would actually return before you hit the exception.

Calling SSRS Report Server it asked "Authentication Required" window

I have just started working in SSRS and I got a very strange problem i.e. When I am calling report server URL i.e. localhost/Reports
This URL requires Authentication window for Username and password. like this.
If I submitted local system user account information in that case it will appear me report server screen which we want. like this.
I have created a demo web-application and in the default.aspx page I am using ReportViewer to show report and configure it. here is the code which i am using
Default.aspx Page
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="100%">
</rsweb:ReportViewer>
Default.aspx.cs Page
ReportViewer1.ProcessingMode = ProcessingMode.Remote;
IReportServerCredentials irsc = new CustomReportCredentials("username", "password", "India");
ReportViewer1.ServerReport.ReportServerCredentials = irsc;
ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://localhost/Reports");
ReportViewer1.ServerReport.ReportPath = "/SSRS_Demo/Report_CaseMain";
ReportViewer1.ServerReport.Refresh();
CustomReportCredentials.cs Class
public class CustomReportCredentials : IReportServerCredentials
{
// local variable for network credential.
private string _UserName;
private string _PassWord;
private string _DomainName;
public CustomReportCredentials(string UserName, string PassWord, string DomainName)
{
_UserName = UserName;
_PassWord = PassWord;
_DomainName = DomainName;
}
public WindowsIdentity ImpersonationUser
{
get
{
return null; // not use ImpersonationUser
}
}
public ICredentials NetworkCredentials
{
get
{
// use NetworkCredentials
return new NetworkCredential(_UserName, _PassWord, _DomainName);
}
}
public bool GetFormsCredentials(out Cookie authCookie, out string user, out string password, out string authority)
{
// not use FormsCredentials unless you have implements a custom autentication.
authCookie = null;
user = password = authority = null;
return false;
}
}
And while i am running this web-application in that case it will gives me an error i.e.
Please help me out what will I do to resolve these all errors.....
After very long R&D I got a solution. I am using wrong SSRS service URL. I am using localhost/Reports but actually the SSRS Reporting Server URL is localhost/ReportServer. So by using this new Reporting Service URL i got the solution of that problem.
Click on your report on localhost/Reports then goto property of that report. On right hand side there is 'Data Source' click on that. Then chek the radio button 'Credentials stored securely in the report server', here you need to specify your SQL server credentials i.e. User name and password
One Time Activity: Once you click on report it will ask again the username and password first time, to overcome this follow below guidelines.
(i) Open Internet Explorer go to Setting click on Internet options
(ii) Go to Security :-> Local Intranet -> Click on Sites
(iii) Click Advanced:
(iv) Add Site: ServerIP Addr (ex.172.16.2.224 or localhost) and then Close.

ajaxcontroltoolkit setting hidden value after asyncfileupload has completed

I have an asyncfileupload control that I'm using from the ajaxcontroltoolkit. On the file complete in the code behind I process the file and write the information in the file to a database. I get the id of the record from the database, and this needs to be written to an asp hidden field. I've tried just setting the value:
fldImageID.Value = pimg.IdImageGroup.ToString();
I've tried Registering a script like I've seen in an example on a website:
ScriptManager.RegisterClientScriptBlock(
ImageFileUploader,
ImageFileUploader.GetType(),
"script1",
"alert('hi'); top.document.getElementById('"
+ fldImageID.ClientID
+ "').value='"
+ pimg.IdImageGroup.ToString()
+ "'; top.document.getElementById('"
+ lblError.ClientID
+ "').innerHTML = 'image uploaded'",
true);
I've just tried embedding javascript in a response.Write call from the method I've set to process the uploaded file. Nothing I've done has worked so far. After I've done everything the hidden field still does not contain the required value.
This is pretty easy with jQuery. Have an html hidden input control placed in your page, not the asp:hidden input control. Add a class lets say "hiddenPhoto" to your html hidden control.
so lets say our control html is like this
<input type="hidden" class="hiddenPhoto" runat="server" id="hdPhotoName" />
Now access it using class selector in your OnClientUploadComplete js method and set its value. Have it declared runat="server" in order to access its value on the server side.
Regards
I found an acceptable solution back when I was working on this. And since then I've received emails from people who have had the same problem and have been asking if I found a solution. So I'm presenting it here, stripping out any extraineous code:
From the user control that has the FileUpload control I first set the session variable on the back side in the FileUploadComplete handler:
*in the ascx file (upload_chart.ascx) I have the AsyncFileUpload, what is important is the OnUploadComplete and the OnClientUploadComplete:*
<ajaxToolkit:AsyncFileUpload
OnUploadedComplete="FileUploadComplete1"
OnClientUploadComplete="UploadComplete1"
ID="ImageFileUploader"
runat="server" />
*in the code behind of the ascx file (upload_chart.ascx.cs) I handle the FileUploadComplete:*
public void FileUploadComplete1(object sender, EventArgs e)
{
try
{
if (ImageFileUploader.FileBytes.Length > 0)
{
// File data is in ImageFileUploaded.FileBytes
// Save it however you need to
// I saved it to a database, in a DBImage Object class I created
// DBImage is specific to my application
ODS.Entity.DBImage pimg =
ODS.Data.DataRepository.SaveImageBytes(ImageFileUploaded.FileBytes);
// Set the ImageID1 in the session
Session["ImageID1"] = pimg.IdImageGroup.ToString();
}
else
{
// error handling for an empty file, however you want to handle it
}
}
catch (Exception Ex)
{
// error handling for an unhandled exception, whatever you want to do here
}
}
Javascript and script methods are used to set the value on the page, here is my codebehind for the script method:
// on the aspx page code behind (chartofthedayadmin.aspx.cs) I have the webmethod:
[System.Web.Services.WebMethod]
public static string GetImageID1()
{
System.Web.SessionState.HttpSessionState Session = System.Web.HttpContext.Current.Session;
String retval = Session["ImageID1"].ToString();
Session["ImageID1"] = null;
return retval;
}
Here is the javascript:
// on the aspx front end (chartofthedayadmin.aspx) I have the javascript
// to call the Web method and the javascript failed message:
function UploadComplete1() {
var str = PageMethods.GetImageID1(uploadSuccess1, uploadFailed);
}
function uploadFailed() {
alert('error occurred or some meaningfull error stuff');
}
*// javascript on the user control (upload_chart.ascx) to set the value of the hidden field*
function uploadSuccess1(result) {
document.getElementById('<%= fldImageID.ClientID %>').value = result;
}
note: Make sure your scriptmanager has EnablePageMethods="true".
The better and more simple solution is in code behind:
string script = String.Format("top.document.getElementById('hdnFilename').value='{0}';", safeFilename);
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "hdnFilenameFromCodeBehind", script, true);
In my case, safeFilename is the unique filename, after handling duplicate filename, i.e. sample_5.png in the 5th upload of sample.png.
See http://forums.asp.net/t/1503989.aspx