Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a code on my web application that exports a report in pdf. whenever i click my export button i get "unknown database connector error. below is the code

if (drpTerm.Text == "First Term")
{
DataTable stud = getClassDetail(ClassID, SessID);
DataSet cds = new DataSet();
cds.Tables.Add(stud);

int Ccount = cds.Tables[0].Rows.Count;
foreach (DataRow erow in cds.Tables[0].Rows)
{
int StudentID = int.Parse(erow["StudentID"].ToString());
UpdateFirstTermClassCount(StudentID, SessID, ClassID, Ccount);
}

DataTable std = getClassDetail(ClassID, SessID);
DataTable sess = loadSess(SessID);
DataTable cls = loadClass(ClassID);
DataTable dft = getFirstTermExamScore(SessID, ClassID);
DataTable dftft = getFirstTermFirstTestScore(SessID, ClassID);
DataTable dftst = getFirstTermSecondTestScore(SessID, ClassID);
DataTable dfttt = getFirstTermThirdTestScore(SessID, ClassID);
DataTable dftt = getFirstTermTotalScore(SessID, ClassID);
DataSet dss = new DataSet();

dss.Tables.Add(dft);
dss.Tables.Add(sess);
dss.Tables.Add(cls);
dss.Tables.Add(std);
dss.Tables.Add(dftft);
dss.Tables.Add(dftst);
dss.Tables.Add(dftt);
dss.Tables.Add(dfttt);

SchoolMgt.termreport.first reports = new SchoolMgt.termreport.first();
if (dss.Tables[0].Rows.Count > 0)
{
ReportDocument crystalReport = new ReportDocument(); // creating object of crystal report
crystalReport.Load(Server.MapPath("~/termreport/first.rpt")); // path of report
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;

// Once I have the data I need to apply it to the connection of the report
ConnectionInfo crConnection = new ConnectionInfo();
crConnection.UserID = "";
crConnection.ServerName = "";
crConnection.DatabaseName = "";
crConnection.Password = "";

crystalReport.Database.Tables["FirstTermExams"].SetDataSource(dft);
crystalReport.Database.Tables["FirstTermThirdTestScore"].SetDataSource(dfttt);
crystalReport.Database.Tables["FirstTermSecondTestScore"].SetDataSource(dftst);
crystalReport.Database.Tables["FirstTermTotal"].SetDataSource(dftt);
crystalReport.Database.Tables["StudentDetail"].SetDataSource(std);
crystalReport.Database.Tables["FirstTermFirstTestScore"].SetDataSource(dftft);
crystalReport.Database.Tables["Session"].SetDataSource(sess);
crystalReport.Database.Tables["Class"].SetDataSource(cls);

//crystalReport.SetDataSource(dss.Tables[0].DefaultView);
CrTables = crystalReport.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}

crystalReport.SetParameterValue("paraSessID", int.Parse(Session["SessID"].ToString()));
crystalReport.SetParameterValue("paraClassID", int.Parse(Session["ClassID"].ToString()));

CrystalReportViewer1.ReportSource = crystalReport;

crystalReport.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, true, "First Term Report");
//here i have used [ CrystalDecisions.Shared.ExportFormatType.PortableDocFormat ] to Export in PDF
}

This is the error message:
Unknown Database Connector ErrorFailed to retrieve data from the database.Error in File first 5228_3548_{5AAED871-9021-4B62-9F74-EF2D34C7A07E}.rpt:
Unknown Database Connector Error

Hope someone can figure this out.
i run windows 7 and my crystal report version is 13

What I have tried:

i have tried to verify database and altered my code a little but still the same error.
Posted
Updated 26-Apr-16 14:19pm

1 solution

You have set your ConnectionInfo to blank.
You need to set the Server, Database, User & Password or Integrated Security to true.

The following code is what I use when I create the ConnectionInfo;
C#
ConnectionInfo crConn = new ConnectionInfo();
crConn.Servername = "myServerName";
crConn.DatabaseName = "myDbName";
crConn.IntegratedSecurity = false;
crConn.UserID = "muUserName";
crConn.Password = "myPassword";
ReportDocument rptDoc = new ReportDocument();
rptDoc.Load("myPath");
Tables rptTables = rptDoc.Database.Tables;
for(int i = 0; i < rptTables.Count; i++)
{
    Table rptTbl = rptTables[i];
    TableLogOnInfo tblInfo = tblRpt.LogOnInfo;
    tblInfo.ConnectionInfo = crConn;
    tblInfo.ApplyLogOnInfo(tblInfo);
}

If Sub Reports exist you need to do the same for each Table in each Sub Report

Kind Regards
 
Share this answer
 
Comments
femrock1 26-Apr-16 21:28pm    
Forgive me but my ConnectionInfo() isn't really blank. I only left that bit out of for security reasons.
femrock1 26-Apr-16 23:18pm    
i tried applying "integrated security = true" but it made no difference n when i also tried using your code as a sample, everything within the "for loop" was in error.
an0ther1 28-Apr-16 18:28pm    
Sorry femrock1 was unavailable till today.
You need references to CrystalDecisions.CrystalReports.Engine, CrystalDecisions.Shared & CrystalDecisions.Web - which you probably already have.
Additionally you need to add the relevant "using" statements if you do not want to fully qualify your paths.
I have the following using statements.
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;

I can see you have updated your code to fully qualify the Table object - this is most likely why you are getting an error - the Table reference is ambiguous if you have System.UI.WebControls listed in your using statements, hence the line
Table rptTbl = rptTables[i];
needs to be
CrystalDecisions.CrystalReports.Engine.Table tblRpt = tblsRpt[i];

If you can run the Report outside of Crystal - am assuming it is connecting to a SQL DB or similar - you don't all the code like
crystalReport.Database.Tables["FirstTermExams"].SetDataSource(dft);

When you set the TableLogOnInfo you are telling Crystal where to get the data & the username & password to use.

Kind Regards
femrock1 3-May-16 14:51pm    
Thanks so much for your insight. The error code is gone n my pdf prints.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900