An unhandled exception of type 'System.StackOverflowException' occurred in PointerTemplateUtility.exe - c#-3.0

Exception is popping in below code under:- "DataSet ds = new DataSet();"
public DataSet GetCommandResponse(int ID)
{
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand("WEB_GetInOutMsgHandlerResponse");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#ID", SqlDbType.Int).Value = ID;
ds = GenericStatementReturnDataSet(cmd, ds, "Unable to fetch template ID");
return ds;
}
It works fine in Most of the time without exception in sometime it throws an exception

Related

SAP Crystal Report : Subreport not showing data in production

I have a main report and 5 subreports, everything is working well except 1 subreport.
In development mode when I preview the main report all the subreports showing data perfectly, especially the subreport "Symptom/s" is fine:
But in production mode, the subreport "Symptom/s" is not coming:
private void loadReport(Int64 appointmentID)
{
try
{
rd = new ReportDocument();
//For main patient record
SqlCommand cmd1 = new SqlCommand("st_getPatientBill", MainClass.con);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.AddWithValue("#appID", appointmentID);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
rd.Load(Application.StartupPath + "\\Reports\\PrescriptionReport.rpt");
rd.SetDataSource(dt1);
ConnectionInfo ci = new ConnectionInfo();
ci.DatabaseName = "cms";
ci.UserID = "sa";
ci.Password = "12345";
ci.ServerName = "DESKTOP-753VMJS";
Tables tables = rd.Database.Tables;
SqlCommand cmd4 = new SqlCommand("st_getInternalMedicine", MainClass.con);
cmd4.CommandType = CommandType.StoredProcedure;
cmd4.Parameters.AddWithValue("#appID", appointmentID);
SqlDataAdapter da4 = new SqlDataAdapter(cmd4);
DataTable dt4 = new DataTable();
da4.Fill(dt4);
rd.Subreports[0].SetDataSource(dt4);
//For external medicine
SqlCommand cmd3 = new SqlCommand("st_getExternalMedicine", MainClass.con);
cmd3.CommandType = CommandType.StoredProcedure;
cmd3.Parameters.AddWithValue("#appID", appointmentID);
SqlDataAdapter da3 = new SqlDataAdapter(cmd3);
DataTable dt3 = new DataTable();
da3.Fill(dt3);
rd.Subreports[0].SetDataSource(dt3);
//For disease
SqlCommand cmd5 = new SqlCommand("st_getPatientDiseaseWRTAppointment", MainClass.con);
cmd5.CommandType = CommandType.StoredProcedure;
cmd5.Parameters.AddWithValue("#appID", appointmentID);
SqlDataAdapter da5 = new SqlDataAdapter(cmd5);
DataTable dt5 = new DataTable();
da5.Fill(dt5);
rd.Subreports[0].SetDataSource(dt5);
//For symptoms
SqlCommand cmd6 = new SqlCommand("st_getPatientSymptomsWRTAppointment", MainClass.con);
cmd6.CommandType = CommandType.StoredProcedure;
cmd6.Parameters.AddWithValue("#appID", appointmentID);
SqlDataAdapter da6 = new SqlDataAdapter(cmd6);
DataTable dt6 = new DataTable();
da6.Fill(dt6);
rd.Subreports[0].SetDataSource(dt6);
//For tests
SqlCommand cmd7 = new SqlCommand("st_getPatientTestWRTAppointment", MainClass.con);
cmd7.CommandType = CommandType.StoredProcedure;
cmd7.Parameters.AddWithValue("#appID", appointmentID);
SqlDataAdapter da7 = new SqlDataAdapter(cmd7);
DataTable dt7 = new DataTable();
da7.Fill(dt7);
rd.Subreports[0].SetDataSource(dt7);
//For internal medicine
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
TableLogOnInfo tableLogonInfo = table.LogOnInfo;
tableLogonInfo.ConnectionInfo = ci;
table.ApplyLogOnInfo(tableLogonInfo);
}
crystalReportViewer1.ReportSource = rd;
crystalReportViewer1.RefreshReport();
}
catch (Exception ex)
{
if (rd != null)
{
rd.Close();
}
}
}
The details are above
I can recommend checking the following:
a) try to find all tables, objects in the report which don't work
(specially try to connect the subreport to different development server in design time it will unveil you hidden dependency of objects in the subreport
b) don't forget to reimport the subreport after you finished any updates :)
b) try to connect all table objects by the following procedure:
(apply it on main report (_reportDocument)
CrystalDecisions.Shared.TableLogOnInfo tableLogOnInfo = new CrystalDecisions.Shared.TableLogOnInfo();
tableLogOnInfo.ConnectionInfo.ServerName = this.DbServer;
tableLogOnInfo.ConnectionInfo.DatabaseName = this.DbCatalog;
tableLogOnInfo.ConnectionInfo.Password = this.DbPassword;
tableLogOnInfo.ConnectionInfo.UserID = this.DbUser;
tableLogOnInfo.ConnectionInfo.IntegratedSecurity = this.DbIntegratedSecurity;
foreach (Table tbl in _reportDocument.Database.Tables)
{
tbl.ApplyLogOnInfo(tableLogOnInfo);
}
foreach (Section sec in _reportDocument.ReportDefinition.Sections)
{
foreach (ReportObject obj in sec.ReportObjects)
{
if (obj.Kind == CrystalDecisions.Shared.ReportObjectKind.SubreportObject)
{
string subDocName = ((SubreportObject)obj).SubreportName;
ReportDocument subDoc = ((SubreportObject)obj).OpenSubreport(subDocName);
foreach (Table tbl in subDoc.Database.Tables)
{
tbl.ApplyLogOnInfo(tableLogOnInfo);
}
}
}
}
P.

I need help for implementing Drool Fluent ApI for dynamically generated DRL file usi ng Kie file system

I was successfully able to generate drool file dynamically using drool fluent api.But my issue is I am not able to write this file in memory area using KieFileSystem API.That is resulting in runtime exception can not find kie module.Below is the same
package com.nagarro;
global fact.OutputData output;
rule "rule1"
when
GenericEvent( cost>500 )
then
output.setDiscount(10)
end
Exception in thread "main" java.lang.RuntimeException: Cannot find KieModule: org.default:artifact:1.0.0-SNAPSHOT
at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:97)
at main.Launcher.evaluate(Launcher.java:67)
at main.Launcher.main(Launcher.java:58)
I have already validate the structure of drl file using drool verifier.
Below is code I am using for the same.
public class Launcher {
public static void main(final String[] args) throws Exception {
/* PackageDescr pkg = DescrFactory.newPackage()
.name("org.drools.example").newImport().target("java.util.ArrayList").end()
.newImport().target("java.util.ArrayList").end()
.newImport().target("java.util.Vector").end()
.newRule().name("alert")
.lhs()
.and()
.pattern("Foo").id( "$foo", false ).constraint("bar==baz").constraint("x>y").end()
.not().pattern("Bar").constraint("a+b==c").end().end()
.end()
.end()
.rhs("System.out.println;"+"/n"+"System.out.println;").end()
.getDescr();*/
PackageDescr desc2 = DescrFactory
.newPackage()
.name("com.nagarro;")
.newGlobal().type("fact.OutputData").identifier("output;")
.end()
.newRule().name("rule1")
.lhs()
.pattern("GenericEvent").constraint("cost>500")
.end()
.end()
.rhs(" output.setDiscount(10)")
.end()
.getDescr();
DrlDumper dumper=new DrlDumper();
String drl=dumper.dump(desc2);
System.out.print(drl);
// verify(drl);
evaluate(drl, new OrderEvent());
}
static private void evaluate(final String drl, final Event event) throws Exception {
KieServices kieServices = KieServices.Factory.get();
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
kieFileSystem.write("src/main/resources/rule.drl", drl);
kieServices.newKieBuilder(kieFileSystem).buildAll();
KieContainer kieContainer = kieServices.newKieContainer(kieServices.getRepository().getDefaultReleaseId());
StatelessKieSession statelessKieSession = kieContainer.getKieBase().newStatelessKieSession();
//HashMap<String,Object> outputMap = new HashMap<>();
OutputData outData = new OutputData();
statelessKieSession.getGlobals().set("output", outData);
HashMap<String, Object> inputMap = new HashMap<>();
inputMap.put("price", 1000);
GenericEvent evt = new GenericEvent();
evt.setInputmap(inputMap);
evt.setCost(1000);
statelessKieSession.execute(evt);
System.out.println(outData.getDiscount());
}
public static void verify(final String drl) {
// Create verifier builder [1]
VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
// Create verifier [2]
Verifier verifier = vBuilder.newVerifier();
// Add Resources you want to verify [3]
verifier.addResourcesToVerify(new ClassPathResource("generic.drl",Launcher.class),
ResourceType.DRL );
// Run the verification rules [4]
verifier.fireAnalysis();
// Get the result object [5]
VerifierReport result = verifier.getResult();
System.out.println(result);
// Print the the errors [6]
for(VerifierMessageBase base: result.getBySeverity( Severity.ERROR ) ){
System.out.println( base );
}
}
}
For writing the drl as file use:
kieFileSystem.write("src/main/resources/rule2.drl", kieServices.getResources().newReaderResource(
new StringReader(drl)));
For validating the drl
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem).buildAll();
// check there have been no errors for rule setup
Results results = kieBuilder.getResults();
if (results.hasMessages(Message.Level.ERROR)) {
System.out.println(results.getMessages());
throw new IllegalStateException("### errors ###");
}
KieContainer kieContainer = kieServices.newKieContainer( kieBuilder.getKieModule().getReleaseId());
KieSession kieSession = kieContainer.newKieSession();
For evaluating rules:
kieSession.insert(inputData);
kieSession.setGlobal("output", outData);
kieSession.fireAllRules();
kieSession.dispose();

Login error when input wrong credentials " An unhandled exception occurred during the execution of the current web request

These in ASP.NET application of which I am starting to learn. There is an error stating System.IndexOutOfRangeException: UserId.
Here is the code:
protected void ValidateUser(object sender, EventArgs e)
{
int userId = 0;
string roles = string.Empty;
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("Validate_User"))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#Username", Login1.UserName);
cmd.Parameters.AddWithValue("#Password", Login1.Password);
cmd.Connection = con;
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
userId = Convert.ToInt32(reader["UserId"]);
roles = reader["Roles"].ToString();
con.Close();
}
switch (userId)
{
case -1:
Login1.FailureText = "Username and/or password is incorrect.";
break;
case -2:
Login1.FailureText = "Account has not been activated.";
break;
default:
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, Login1.UserName, DateTime.Now, DateTime.Now.AddMinutes(2880), Login1.RememberMeSet, roles, FormsAuthentication.FormsCookiePath);
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
if (ticket.IsPersistent)
{
cookie.Expires = ticket.Expiration;
}
Response.Cookies.Add(cookie);
Response.Redirect(FormsAuthentication.GetRedirectUrl(Login1.UserName, Login1.RememberMeSet));
break;
}
}
}
}
}
Here is the Image to the error
Error message

Crystal Report doesn't show data when generated

When I generate it on runtime, it doesn't show any data. But it does when I check on the 'Main Report Preview' of VS 2010. I have also checked my stored procedure, it does produce data when I execute it. What seems to be the problem?
This is my code in page_load:
protected void Page_Load(object sender, EventArgs e)
{
string municipio = Request.QueryString["municipio"];
string ano = Request.QueryString["ano"];
string cnpj = Server.UrlDecode(Request.QueryString["cnpj"]);
DataTable dt;
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
using (SqlConnection cnn = new SqlConnection(CS))
{
cnn.Open();
//stored procedure
SqlCommand cmd = new SqlCommand("spConsultaRelatorioCompleto", cnn);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#ano", ano);
cmd.Parameters.AddWithValue("#municipio", municipio);
cmd.Parameters.AddWithValue("#cnpj", cnpj);
//read access to the database
SqlDataReader dr = cmd.ExecuteReader();
SqlDataAdapter da = new SqlDataAdapter(cmd);
//datatable with data
dt = new DataTable("dt");
//datatable with datareader's data
dt.Load(dr);
da.Fill(dt);
}
ReportDocument MeuRelatorio = new ReportDocument();
MeuRelatorio.Load(Server.MapPath("RelatorioConvenio.rpt"));
MeuRelatorio.SetDataSource(dt);
CrystalReportViewer1.ReportSource = MeuRelatorio;
}
}
}
I give some values in another webform when I click the button below:
protected void btnExport_Click(object sender, EventArgs e)
{
Response.Redirect("RelatorioGerado.aspx?municipio=" + ddlmunicipioconvenente.Text + "&cnpj=" + Server.UrlEncode(tbcnpjconvenente.Text) + "&ano=" + tbAno.Text);
}

Report opens Blank in ADF

I have report1.jrxml which have simple SQL query with no parameters and runs fine in iReport. I want to open this report through ADF.
my reportAction method is as follows:
public void reportAction(FacesContext ctx,OutputStream output) throws FileNotFoundException,NamingException,
SQLException, IOException, JRException,
ClassNotFoundException,
InstantiationException,
IllegalAccessException {
File input = null;
Connection conn = null;
Map reportParameters = new HashMap();
bindings = this.getBindings();
ctx = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse)ctx.getExternalContext().getResponse();
String reportPath = ctx.getExternalContext().getInitParameter("reportpath");
input = new File(reportPath+"report1.jasper");
if(bindings!=null){
OperationBinding ob = bindings.getOperationBinding("getCurrentConnection");
ob.execute();
conn = (Connection)ob.getResult();
if(input.getPath()!=null&&reportParameters!=null&&conn!=null){
JasperPrint print = JasperFillManager.fillReport(input.getPath(),reportParameters,conn);
response.addHeader("Content-disposition", "attachment;filename=report1.pdf");
output = response.getOutputStream();
String userName = "ilpa";
File outPutPDF = new File("D:/jdev libs/reports/report1.pdf");
JasperExportManager.exportReportToPdfStream(print, output);
JasperExportManager.exportReportToPdfFile(print,outPutPDF.getPath());
JasperExportManager.exportReportToPdfStream(print, output);
output.flush();
output.close();
}
}
else{
ctx.addMessage(null,new FacesMessage("No bindings configured for this page"));
}
}
What could be wrong?
I have solved the issue myself.
The root cause was I was giving a wrong path in web.xml.
That is, I had report1.jrxml in two locations. The actual report I was using was in a different location.