An error has occurred during report (rdlc) processing - report

I got the error While I am creating RDLC report.
Error is that
" An error has occurred during report processing.
Cannot create a connection to data source 'ds_SalesQuotation'.
Calling 'Read' when the data reader is closed is not a valid operation.
Invalid attempt to call Read when reader is closed. "
I create ds_SalesQuotation.xsd file.
In rdlc report give dataset name as 'dsSalesQuotation' and set datasourse as 'ds_SalesQuotation'
my code is on reportviewr(.aspx)
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
using (BillingAppEntities context = new BillingAppEntities())
{
var val = context.Sp_SalesQuotation(id);
ReportDataSource rd = new ReportDataSource("dsSalesQuotation", val);
ReportViewer1.LocalReport.DataSources.Add(rd);
ReportViewer1.LocalReport.Refresh();
}
}
}
Is there any mistaken in my code.please check it anybody..

I got my error.I re-write the above code,that is given below.
Now it is working
private void PopulateReport(int id)
{
List<Sp_SalesQuotation_Result> ls = new List<Sp_SalesQuotation_Result>();
using (BillingAppEntities context = new BillingAppEntities())
{
ls = context.Sp_SalesQuotation(id).ToList();
}
ReportDataSource rd = new ReportDataSource("dsSalesQuotation", ls);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(rd);
ReportViewer1.LocalReport.Refresh();
}

Related

Aspx and connecting to a access database on a share

Im trying to make a aspx application that connects to a access database on a share.
the path is correct, when i copy paste it in a run screen it opens a database right away.
The weird thing is that the exception that im getting is this, however the database is not a mdb and not in that location either.(it was dutch I translated it, might not be 100% correct translation):
Cant find file C:\Program Files (x86)\IIS Express\dbo.mdb
This is my code:
The exception is fired on the ExecuteReader
namespace AssetDB
{
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_zoek_Click(object sender, EventArgs e)
{
if (txt_name.Text.Length < 4)
return;
using (OleDbConnection conn = new OleDbConnection(#"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\netwerk\data\TeamFolders\ICT\Asset Database\_Backend\Assets_be.accdb; "))
using (OleDbCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "Select * from dbo.Bruikleen_Laptops where Laptop_id = #id";
cmd.Parameters.AddWithValue("#id", txt_name.Text);
conn.Open();
using (OleDbDataReader r = cmd.ExecuteReader())
while(r.Read())
{
drop_gevonden.Items.Add(r["Laptop_id"].ToString());
}
conn.Close();
}
}
}
}

A data source instance has not been supplied for the data source 'DataSource1'

The following code is working well to show a rdlc report perfectly. But problem is
there is an error after load the page first time A data source instance has not been supplied for the data source 'StudentTranscript' while the data source name is correct.
protected void btnLoad_Click(object sender, EventArgs e)
{
List<rStudentTranscript> list = StudentManager.GetStudentTrancriptById(studentId);
ReportDataSource rds = new ReportDataSource("StudentTranscript", list);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(rds);
}
}
How to solve this ?
Try adding
ReportViewer1.LocalReport.Refresh();

how to insert data from csv file into database using asp.net

I am trying to insert data that is saved in csv format.i tried the below code but the problem is when i run the code it only save data from the second line.can anyone correct my code so that i can save my data from the first line.
CODE:-
protected void Page_Load(object sender, EventArgs e)
{
csvInsert();
}
public void csvInsert()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connectme"].ConnectionString);
conn.Open();
//DataTable dt = new DataTable("insert");
string filename = "C:\\Users\\Aowi\\Desktop\\asdf.csv";
SqlTransaction transaction = conn.BeginTransaction();
try
{
using (StreamReader file = new StreamReader(filename))
{
CsvReader csv = new CsvReader(file, true, '\t');
SqlBulkCopy copy = new SqlBulkCopy(conn, SqlBulkCopyOptions.KeepIdentity, transaction);
copy.DestinationTableName = "[Live]";
copy.WriteToServer(csv);
transaction.Commit();
}
}
catch (Exception ex)
{
transaction.Rollback();
}
finally
{
conn.Close();
}
}
Saved in Database as:-
csv file is:-
1,Germany,? - ?,Portugal
2,half-time,(? - ?),
3
4,Milorad Mazic (Serbia),
5,Iran,? - ?,Nigeria
6,half-time,(? - ?),
7
8,Carlos Vera (Ecuador),
9,Ghana,? - ?,USA
10,half-time,(? - ?),
Desired output is insert each and every data from the csv file to each cell in database.
It looks like the CSV reader expects a header row. Try adding a header to the top and see if that resolves. Try passing FALSE to the CSVReader, as well. It looks like that flag might be used to signify if you have a header row or not.

No valid report source is available- crystal reports

I have created a report using crystal reports. I am using visual studio 2010. The problem occurs when I try to go to another page. When I try to navigate to page 2 or last page the error No valid report source is available appears on the screen. Does anyone have any idea what I need to do? Thanks for your time
Store you report in Session and then give report source from session on page post back
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
try
{
CrystalReportViewer1.ReportSource = (ReportDocument)Session["Report"];
CrystalReportViewer1.RefreshReport();
CrystalReportViewer1.DataBind();
}
catch (Exception ex)
{
// throw;
}
}
}
protected void CrystalReportViewer1_PreRender(object sender, EventArgs e)
{
}
protected void btnPrint_Click(object sender, EventArgs e)
{
ReportDocument rptDoc = new ReportDocument();
rptDoc.Load(Server.MapPath("Reports\\BalanceReportNew\\BalanceReport.rpt"));
rptDoc.SetDataSource(ReportData());
Session["Report"] = rptDoc;
CrystalReportViewer1.ReportSource = rptDoc;
CrystalReportViewer1.RefreshReport();
CrystalReportViewer1.DataBind();
}
public DataTable ReportData()
{
string ClassName = ddlClass.SelectedValue;
string Division = ddlDivison.SelectedValue;
string Subject = ddlSubjects.SelectedValue;
DataTable ReportData = objRpt.getReportData(ClassName, Division, Subject);
return ReportData;
}
The following 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("mostDialledNumbers.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();
}
Try using the solution in this thread:
No Valid report source is available
From what it says, you should be able to make it work by providing ConnectionInfo and ReportSource in the code.
#Simple Solution
I have just Solved this problem using CrystalReportViewer Navigate Event
in View report Button i have saved report document in a session
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
' -- the ds is dataset variable containing data to be displayed in the report
rptDoc.SetDataSource(ds)
Session.Add("rptdoc", rptDoc)
CrystalReportViewer1.ReportSource = rptDoc
End Sub
then in Navigate event of CrystalReportViewer i set the CrystalReportViewer data source to the Session
Protected Sub j(ByVal source As Object, ByVal e As CrystalDecisions.Web.NavigateEventArgs) Handles CrystalReportViewer1.Navigate
rpt.SetDataSource(ds)
CrystalReportViewer1.ReportSource = session("rptdoc")
End Sub
So each time before you navigate to another page in the report , CrystalReportViewer data source is set to the report document saved in the session.
Thanks to #Răzvan Panda.
Full code is given here.
protected void Page_Load(object sender, EventArgs e){
CrystalDecisions.CrystalReports.Engine.ReportDocument report =
new CrystalDecisions.CrystalReports.Engine.ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
report.Load(Server.MapPath("~/Reports/Monthly/CrMonthly.rpt"));
crConnectionInfo.ServerName = ConfigurationManager.AppSettings["Server4Crystal"].ToString();//[SQL SERVER NAME]
crConnectionInfo.DatabaseName = ConfigurationManager.AppSettings["Database4Crystal"].ToString();//[DATABASE NAME]
crConnectionInfo.UserID = ConfigurationManager.AppSettings["User4Crystal"].ToString();//[DB USER NAME]
crConnectionInfo.Password = ConfigurationManager.AppSettings["Password4Crystal"].ToString(); //[DB PASSWORD]
//LOOP THROUGH EACH TABLE & PROVIDE LOGIN CREDENTIALS
CrTables = report.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
//PROVIDE PARAMETERS TO CRYSTAL REPORT, IF REQUIRED.
ParameterField paramField = new ParameterField();
ParameterFields paramFields = new ParameterFields();
ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
paramField.Name = "PARAMETER_NAME";
paramDiscreteValue.Value = "PARAMETER_VALUE";
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
//ADD MORE PARAMETERS, IF REQUIRED....
StoreMonthlyViewer.ParameterFieldInfo = paramFields;
StoreMonthlyViewer.ReportSource = report;
//FINALLY REFRESH REPORT
StoreMonthlyViewer.RefreshReport();
StoreMonthlyViewer.ToolPanelView = CrystalDecisions.Web.ToolPanelViewType.None;
}
Well its not a big problem you just need to create session of your data source. Then pass it on page load. All crystal report function will work properly.
If you need any further help or code, let me know.
As stated in other answers kind of. Store the ReportDocument in a session (or something) and set the ReportSource.
Example:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["ReportSource"] != null)
{
CrystalReportViewer1.ReportSource = (ReportDocument) Session["ReportSource"];
}
else
{
ReportDocument reportDocument = new ReportDocument();
reportDocument.Load("MyReport.rpt");
CrystalReportViewer1.ReportSource = reportDocument;
Session["ReportSource"] = reportDocument;
}
}
try looking for some parameter that your report does not contain
usually it happens when you insert some parameter in code and your report does not contain that parameter

Silverlight OOB WebBrowser Exception

I've got an oob app with a webbrowser on it.
The webbrowser source is databound with a URI defined by me. The URI has a path to a webpage from my server that displays a PDF file from its hardrive.
Note that all this is done on a local network.
URI example: uri = new Uri(#"http://ServerName/ProjectName/PDFViewer.aspx?pdf=somePDF.pdf");
Page code-behind:
protected void Page_Load(object sender, EventArgs e)
{
string myURL = Request.Url.ToString();
string[] ParamArray = Regex.Split(myURL, "pdf=");
string Params = ParamArray[ParamArray.Length - 1];
if (Params.Length > 0)
{
Filename = Regex.Replace(Params, #"//", #"\\"); ;
if (File.Exists(Filename))
{
Response.ContentType = "Application/pdf";
Response.WriteFile(Filename); //Write the file directly to the HTTP content output stream.
Response.End();
}
else
this.Title = "PDF Not Found";
}
}
protected void Page_Load(object sender, EventArgs e) { string myURL = Request.Url.ToString(); string[] ParamArray = Regex.Split(myURL, "pdf="); //If the URL has parameters, then get them. If not, return a blank string string Params = ParamArray[ParamArray.Length - 1]; if (Params.Length > 0) { //to the called (src) web page Filename = Regex.Replace(Params, #"//", #"\\"); ; if (File.Exists(Filename)) { Response.ContentType = "Application/pdf"; Response.WriteFile(Filename); //Write the file directly to the HTTP content output stream. Response.End(); } else this.Title = "PDF Not Found"; } }
The first time I set the WebBrowser source everything it displays the PDF. But when I set the URI one second time the app throws an exception: Trying to revoke a drop target that has not been registered (Exception from HRESULT: 0x80040100).
I've done a few tests and here are the results:
1º new Uri(#"http://ServerName/ProjectName/PDFViewer.aspx?pdf=somePDF.pdf");
2º new Uri(#"http://ServerName/ProjectName/PDFViewer.aspx?pdf=someOtherPDF.pdf"); ->error
1º new Uri(#"http://ServerName/ProjectName/PDFViewer.aspx?pdf=somePDF.pdf");
2º new Uri(#"http://www.google.com"); ->error
1º new Uri(#"http://www.google.com");
2º new Uri(#"http://www.microsoft.com");
2º new Uri(#"http://ServerName/ProjectName/PDFViewer.aspx?pdf=somePDF.pdf");
3º new Uri(#"http://ServerName/ProjectName/PDFViewer.aspx?pdf=someOtherPDF.pdf"); ->error
I also forgot to say that when running the app from my browser (using a HTMLHost) the pages display just fine. Opening the pages using a browser will also work well.
It must be some problem with my aspx page. Any ideas?
Pedro
I've managed to resolve this by creating a new browser for each page. If you know of a more elegant solution please share.
I am not sure if I'm following the question/problem correctly but maybe loading the pages async and then assigning to webbrowser? Forgive me if I am off-base here.
public void ShowLink(string linkUrl)
{
if (App.Current.IsRunningOutOfBrowser)
{
var pageRequest = new WebClient();
pageRequest.DownloadStringCompleted += pageRequest_DownloadStringCompleted;
pageRequest.DownloadStringAsync(new Uri(linkUrl, UriKind.Absolute));
}
}
void pageRequest_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
webBrowserLink.NavigateToString(e.Result.ToString());
}

Resources