No valid report source is available. in asp.net sap crystal report - visual-studio-2010

I am using Sap Crystal Report in asp.net 2010
It will shows the error no valid report source id available, when i refreshing the report or moving to next page at run time using report viewer tools
and this is my coding,
Dim crdoc5 As New ReportDocument()
Dim crtablogoninfo5 As New TableLogOnInfo
Dim crtabs5 As Tables
If Not IsPostBack Then
crdoc5.Load(Server.MapPath("CrStaffrecruit.rpt"))
Session.Add("CrStaffrecruit", crdoc5)
CrystalReportViewer5.ReportSource = crdoc5
Else
CrystalReportViewer5.ReportSource = Session("CrStaffrecruit")
End If
crdoc5.Load(Server.MapPath("CrStaffrecruit.rpt"))
Dim crconninfo5 As New ConnectionInfo()
rconninfo5.ServerName = "servername"
crconninfo5.DatabaseName = "databasename"
crconninfo5.UserID = "sa"
crconninfo5.Password = ""
crtabs5 = crdoc5.Database.Tables()
For Each crtab5 As CrystalDecisions.CrystalReports.Engine.Table In crtabs5
crtablogoninfo5 = crtab5.LogOnInfo
crtablogoninfo5.ConnectionInfo = crconninfo5
crtab5.ApplyLogOnInfo(crtablogoninfo5)
Next
CrystalReportViewer5.ReportSource = crdoc5
CrystalReportViewer5.RefreshReport()
If any one know pls help me...
Thanks in advance

For this please go through the following link
http://forums.sdn.sap.com/thread.jspa?messageID=10951477&#10951477

Although the following code is in C#, it shouldn't be too difficult to translate it to VB and it should solve your issue:
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
//whatever you do when the page is loaded for the first time
//this could even be bindReport();
}
else
{
bindReport();
}
}
public void bindReport()
{
ReportDocument rptDoc = new ReportDocument();
dsSample ds = new dsSample(); // .xsd file name
DataTable dt = new DataTable();
// Just set the name of data table
dt.TableName = "Crystal Report Example";
dt = getMostDialledNumbers(); //This function populates the DataTable
ds.Tables[0].Merge(dt, true, MissingSchemaAction.Ignore);
// Your .rpt file path will be below
rptDoc.Load(Server.MapPath("yourReportFilePath.rpt"));
//set dataset to the report viewer.
rptDoc.SetDataSource(ds);
CrystalReportViewer1.ReportSource = rptDoc;
CrystalReportViewer1.RefreshReport();
//in case you have an UpdatePanel in your page, it needs to be updated
UpdatePanel1.Update();
}

I was experiencing the same problem. In what event are you executing the code you posted? I ask because after much debugging, I discovered that you need to place the code in Page_Load (as opposed to PreRender like I was doing previously...)
Hope this helps.

I have got this problem several times, and the solution is to save the Report Document variable in a session then in the Page_load put the below code:
if (IsPostBack)
{
if (Session["reportDocument"] != null)
{
ReportDocument cr = new ReportDocument();
cr = (ReportDocument)Session["reportDocument"];
CrystalReportViewer1.ReportSource = cr;
CrystalReportViewer1.DataBind();
}
}
NB:
Don't forget to fill the (Session["reportDocument"]) with the Display button.

Go through following link. I resolved same issue with that solution.
http://www.aspsnippets.com/Articles/ASPNet-Crystal-Reports-13-Visual-Studio-2010-CrystalReportViewer-Search-Button-Issue---No-valid-report-source-is-available.aspx

Related

SelectedItem must always be set to a valid value. Windows Phone Local Database

I am using the local database example taht Microsoft created.
I can add items to the list, and delete them. But I now want to select the items and get the text of the item and use that in the next page.
This is the select changed event:
private void allToDoItemsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
NavigationService.Navigate(new Uri("/LiveTimes.xaml?selectedItem=" + allToDoItemsListBox.SelectedIndex, UriKind.Relative));
// string urlWIthData = string.Format("/LiveTimes.xaml?name={0}", " ");
// this.NavigationService.Navigate(new Uri(urlWIthData, UriKind.Relative));
}
Then this is the on page load on the other page.
string selectedIndex = "";
if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
{
int index = int.Parse(selectedIndex);
DataContext = App.ViewModel.HomeToDoItems[index];
}
Then when i use this, the error is on the DataContext line.
Whats the solution?
There is no problem in the above code that you have shown, The actual problem may be in the way how you defined your ViewModel and HomeToDoItems . It helps us to solve your problem, if you can show some of that code.
Also before setting your data to DataContext, try the following steps:
First, make sure you are getting the valid selectedIndex.
var tempData = App.ViewModel.HomeToDoItems[index];
DataContext = tempData;
And then insert a break point at tempData to check whether you are getting the expected data.
This answer may not solve your problem, but guide you in identifying the actual problem.

How to decrease margin programmatically on exported BIRT PDF reports?

Is there a way to decrease the margin of the PDF reports using the BIRT API?
I tried setting the PDF rendering options to:
PDFRenderOption renderOption = new PDFRenderOption();
renderOption.setOutputFormat(PDFRenderOption.OUTPUT_FORMAT_PDF);
renderOption.setOption(IPDFRenderOption.PDF_HYPHENATION, true);
renderOption.setOption(IPDFRenderOption.PDF_TEXT_WRAPPING, true);
renderOption.setOption(IPDFRenderOption.PAGE_OVERFLOW,
IPDFRenderOption.ENLARGE_PAGE_SIZE);
Basically the problem I have is that if I have a longer text in a column (from one of the tables) it will get it on the next line, but if I set the IPDFRenderOption.PDF_HYPHENATION to false I will get the text split right in the middle of the text (see below).
PDF with IPDFRenderOption.PDF_HYPHENATION set to true
PDF with IPDFRenderOption.PDF_HYPHENATION set to false
So, I was trying to set the margin of the PDF to be smaller to overcome this issue, but I don't find any documentation on how to do this with the BIRT API...
There is this suggestion of modifying the master page, but I have way too many reports to modify them by hand.
How should I approach the problem? Is this even possible using the BIRT API?
All I needed to do was to loop through all the handles, test which of them is a MasterPageHandle and call setProperty with these keys:
MasterPageHandle.BOTTOM_MARGIN_PROP
MasterPageHandle.LEFT_MARGIN_PROP
MasterPageHandle.RIGHT_MARGIN_PROP
MasterPageHandle.TOP_MARGIN_PROP
and the DimensionValue I needed.
Code sample
#SuppressWarnings("unchecked")
private void shrinkPageSizeForExport(IReportRunnable reportRunnable) {
DesignElementHandle designHandle = reportRunnable.getDesignHandle();
IElementDefn elementDefn = designHandle.getDefn();
for (int i = 0; i < elementDefn.getSlotCount(); i++) {
SlotHandle slotHandle = designHandle.getSlot(i);
for (DesignElementHandle elementHandle: (List<DesignElementHandle>)slotHandle.getContents()) {
if (!(elementHandle instanceof MasterPageHandle)) continue;
MasterPageHandle mph = (MasterPageHandle)elementHandle;
DimensionValue dv = new DimensionValue(0.1, "cm");
setAllMarginsTo(mph, dv);
}
}
}
private void setAllMarginsTo(MasterPageHandle mph, DimensionValue dv) {
try {
mph.setProperty(MasterPageHandle.BOTTOM_MARGIN_PROP, dv);
mph.setProperty(MasterPageHandle.LEFT_MARGIN_PROP, dv);
mph.setProperty(MasterPageHandle.RIGHT_MARGIN_PROP, dv);
mph.setProperty(MasterPageHandle.TOP_MARGIN_PROP, dv);
} catch (SemanticException se) {
throw new RuntimeException("Cannot set margins for report export!", se);
}
}
Alternate suggestion:
Build a MasterPage in your BIRT library, and use it on all reports. Then all reports it is used on can be updated at one time. If you did not start with library MasterPages, you can replace the report MasterPage with the library master page, quicker then trying to recode them all.
Things like DataSources, and MasterPages are almost always better as library items.

could not select subreport - .rdlc - VS 2010

I had created many reports with VS 2008. Now starting with VS 2010 for new requirement. Please note I am using .rdlc report
I could add subreport control to the report but could not select the available reports. There is no browse button or a dropdown to choose the available .rdlc report.
When I manually type the report name, the reportviewer doesnt show up any subreport. I dont see any error message on the 'Output' window either.
How do I use subreport with VS 2010? Am I missing anything? Any help is appreciated.
I have SQL 2005/2008 (report services installed), VS 2008, VS 2010 installed on the same PC.
First select sub report from Toolbox and put where you want to show.See the image bellow
Now right click on sub report properties and type your sub report name .
Now You have to create a sub report even handler in your .cs file from where you load your report like that:
public Ctor()
{
string path = HttpContext.Current.Server.MapPath("Your Report path");
ReportViewer1.Reset(); //important
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local;
ReportViewer1.LocalReport.SubreportProcessing += Process_Subreport;
LocalReport objReport = ReportViewer1.LocalReport;
objReport.ReportPath = path;
// Add Parameter If you need
List<ReportParameter> parameters = new List<ReportParameter>();
parameters.Add(new ReportParameter("Name", Value));
ReportViewer1.LocalReport.SetParameters(parameters);
ReportViewer1.ShowParameterPrompts = false;
ReportViewer1.ShowPromptAreaButton = false;
ReportViewer1.LocalReport.Refresh();
//Add Datasourdce
ReportDataSource reportDataSource = new ReportDataSource();
reportDataSource.Name = "Datasource Name Used due to report design";
reportDataSource.Value = DataSourceValue;
objReport.DataSources.Add(reportDataSource);
objReport.Refresh();
}
Now Create Even Handler Method to load sub report details.
private void Process_Subreport(object sender, SubreportProcessingEventArgs e)
{
//You can get parameter from main report
int paramname = int.Parse(e.Parameters[0].Values[0].ToString());
//You can also add parameter in sub report if you need like main report
//Now add sub report data source
e.DataSources.Add(new ReportDataSource("DataSource Name",DataSourceValue)));
}
I think it will be works for you.Thank you.

Dynamically added Raddocks Optimization?

We have a optimization problem regarding rad dock controls. The requirement of project is such that we are creating dynamic raddocks on the fly and adding it to a raddockzone, then we are saving the raddock "type" etc in a mssql db. We also have a collector window/raddockzone in which we have build a functionality where we can drag a dock and save it in collector. As with the first raddockzone we are adding the dock in collector on the fly. Now while adding a dock or moving it to another raddockzones it takes sometime. Our client is comparing it with the example of the demo link : http://demos.telerik.com/aspnet-ajax/dock/examples/content/defaultcs.aspx
Following is our code snippet to add dock on the fly:
private RadDockNew CreateRadDock()
{
//string[] allowedZones = { "RDZCollector", "RadDockZone2" };
int width = Convert.ToInt32((hdnWidth.Value == "") ? "520" : hdnWidth.Value);
RadDockNew dock = new RadDockNew();
dock.DockMode = DockMode.Docked;
dock.UniqueName = Guid.NewGuid().ToString().Replace("-", "a");
dock.ID = string.Format("RadDock{0}", dock.UniqueName);
//dock.Title = dock.UniqueName.Substring(dock.UniqueName.Length - 3);
dock.Width = Unit.Pixel(width);
dock.CssClass = "RadDockZoneMain";
//dock.AllowedZones = allowedZones;
dock.Style.Add("min-height", "290px");
dock.OnClientDockPositionChanged = "DropInCollector";
//dock.EnableViewState = false;
DockCommand cmd = new DockCommand();
cmd.Name = "Setting";
cmd.Text = "Setting";
cmd.OnClientCommand = "showSettings";
dock.Commands.Add(cmd);
DockCommand dc = new DockCommand();
dc.Text = "Trash";
dc.Name = "Trash";
dc.OnClientCommand = "CloseDock";
dc.CssClass = "rdClose";
dc.AutoPostBack = true;
dock.Commands.Add(dc);
DockToggleCommand cmd2 = new DockToggleCommand();
cmd2.CssClass = "rdCollapse";
cmd2.AlternateCssClass = "rdexpand";
cmd2.OnClientCommand = "ChangeImage";
//DockCommand collapse = new DockCommand();
//collapse.Text = "Collapse/Expand";
//collapse.Name = "Collapse/Expand";
//collapse.OnClientCommand = "CollapseDock";
//collapse.CssClass = "rdCollapse";
dock.Commands.Add(cmd2);
return dock;
}
Please tell if there is any way to optimize / make it faster.
Thanks.
I examined the attached code sample and I think that it is correct. My suggestions are to check if the problem persists if you use other storage medium, instead of a database or if there are client script errors on the page, containing the RadDocks.
As the setup of your project seems to be similar to the one, implemented in the My Portal demo, I would recommend using the example in the Code Library article Saving State of Dynamically Created RadDocks in DataBase using Hidden UpdatePanel as a reference.

Updating an Activity in MS CRM via web service?

I've been trying to do this all morning. Anyone have a code snippet (C#) showing how to update an "activity" within CRM via the webservice?
I can CreateReadUpdateDelete with entities, but I'm not sure how to do it with Activities.
Can't find anything on google either...
What are you specifically looking to update? Basically, updating an activity is just like updating any other entity, you just have to use the task entity.
public void CloseTask(CrmService crmsvc, Guid activityid, DateTime start, DateTime end)
{
ColumnSet cols = new ColumnSet();
cols.Attributes = new string[] { "activityid", "statecode" };
task tsk = (task)crmsvc.Retrieve(EntityName.task.ToString(), activityid, cols);
if(tsk.statecode.Value != TaskState.Open)
return;
tsk.actualstart = new CRMDateTime();
tsk.actualstart.value = start.ToString();
tsk.actualend = new CRMDateTime();
tsk.actualend.value = end.ToString();
crmsvc.Update(tsk);
SetStateTaskRequest state = new SetStateTaskRequest();
state.EntityId = activityid;
state.TaskState = TaskState.Completed;
state.TaskStatus = -1; // Let MS CRM decide this property;
SetStateTaskResponse stateSet = (SetStateTaskResponse)crmsvc.Execute(state);
}
Edit: added some sample code. note, I had to modify what I had to strip some proprietary code, so I don't know if this will actually compile. It's close though.
We can also update a Custom Workflow Activity Using Assembly Versioning. Below link gives more information:
http://msdn.microsoft.com/en-us/library/gg328011.aspx

Resources