Hi all,
I am trying to view
my "CrystalReport4.rpt" and below is the
code im am using and it has been working. However when i added a password to my
access database, when I try to generate a report, I am requested for a password
and even when I try to login, the small interface says "failed to login". I need
a solution within my code using the password to be able to access my access
database.
Below is the code I am using..
{
crystalReportViewer4.Visible = true;
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load("C:/Users/katoto/Documents/Visual Studio
2010/Projects/Genesis Philcollins/Genesis
Philcollins/CrystalReport4.rpt");
ParameterFieldDefinitions crParameterFieldDefinitions;
ParameterFieldDefinition crParameterFieldDefinition;
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = textBox2.Text;
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["bankacid"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Clear();
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
crystalReportViewer4.ReportSource = cryRpt;
crystalReportViewer4.Refresh();
}
Thanks again and Best Regards.

Sudhakar ChaudharyPosted Jan 17, 2013, 10:22 AM
see the attached file..
CrystalReport1 cr = new CrystalReport1();
string databasePath = Application.StartupPath + "\\thyfarm.accdb";
cr.DataSourceConnections[0].SetConnection("MS Access Database", databasePath, "admin", "kyozi");
//here pass your parameter
crystalReportViewer1.ReportSource = cr;
Marvin kakuruPosted Jan 19, 2013, 5:14 PM
sorry for the trouble the code you prescribed has worked perfectly, i just realized the problem all along was the location of my database, so i relocated it to "C:\Users\katoto\Documents\Visual Studio 2010\Projects\Genesis Philcollins\Genesis Philcollins\bin\Debug" and its working well thank you so much
Best Regards.
Marvin kakuruPosted Jan 18, 2013, 12:08 PM
i have download your sample project which is working perfectly. now i have altered my project to yours , but there is a small problem when it comes to setting up the connection using the c sharp database expert connection setup, something i am doing that's not right. my microsoft visual studio is 2010 version and my crystal reports is the 2008 version.
kindly advise me on how you setup your connection in the database expert dialogue.
thanks again
Marvin kakuruPosted Jan 18, 2013, 2:27 AM
I have tried the code and even run the project, but in vain. I still can't get my project to run my crystal reports.
however i just realised that when i was creating the connection between my crystalreport4 and the access database, i had not yet encrypted my access database. i also realised that after protecting my database with a password i can nolonger create a new connection to link my crystalreport4 to database table.
I was thinking something is not right with the way i am trying to link my crystalreport forms to data connections especially now that the database is password protected.
otherwise thanks lot for your support.
Great day.
Marvin kakuruPosted Jan 17, 2013, 5:07 AM
Hai, Sudhakar,
My access database is version (office 2007) and this is my file extension "C:\Users\katoto\Documents\Visual Studio 2010\Projects\Genesis Philcollins\data\thyfarm.accdb"
Kindly insert the code you recommend in my code below because I am now really confused
{
crystalReportViewer4.Visible = true;
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load("C:/Users/katoto/Documents/Visual Studio 2010/Projects/Genesis Philcollins/Genesis Philcollins/CrystalReport4.rpt");
cryRpt.DataSourceConnections[0].SetConnection("Admin","kyozi");
ParameterFieldDefinitions crParameterFieldDefinitions;
ParameterFieldDefinition crParameterFieldDefinition;
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = textBox2.Text;
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["bankacid"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Clear();
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
crystalReportViewer4.ReportSource = cryRpt;
crystalReportViewer4.Refresh();
}
Thanks a lot for your time.
Best regards
Sudhakar ChaudharyPosted Jan 17, 2013, 3:00 AM
This is like a connection string. As you used in your code for save your data.
Something like that…
Provider=Microsoft.ACE.OLEDB.12.0;
Data Source=\\serverName\shareName\folder\myAccess2007file.accdb;
Or like that
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\myAccess2007file.accdb;
Persist Security Info=False;
Or like that
Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\mydatabase.accdb;Uid=Admin;
Pwd=;
if any problem, tell me the your database version(office 2007,10,etc) and file extension (.accdb,.mdb)
Marvin kakuruPosted Jan 17, 2013, 2:31 AM
i have done as you advised however my connection is "Microsoft.ACE.OLEDB.12.0" instead of "Microsoft.ACE.OLEDB.14.0" and i still am unable to login.
should i try using "Microsoft.ACE.OLEDB.14.0"
thanks
Sudhakar ChaudharyPosted Jan 17, 2013, 1:52 AM
//if using security mode
RPT_FORM_B1.DataSourceConnections[0].SetConnection("Microsoft.ACE.OLEDB.14.0", "exercise1.accdb", "Admin", "Kyozi");
//without security mode
RPT_FORM_B1.DataSourceConnections[0].SetConnection("Microsoft.ACE.OLEDB.14.0", "exercise1.accdb", false);
Marvin kakuruPosted Jan 17, 2013, 1:31 AM
Hi sudhakar,
Thanks for your response. According to your advise I have altered my code as below, however I am still failing to get my crystal reports to log into my database."Admin" is the ID and "Kyozi" is the password. Is there any thing am still doing wrong.
Below is the code
{
crystalReportViewer4.Visible = true;
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load("C:/Users/katoto/Documents/Visual Studio 2010/Projects/Genesis Philcollins/Genesis Philcollins/CrystalReport4.rpt");
cryRpt.DataSourceConnections[0].SetConnection("Admin","Kyozi")
ParameterFieldDefinitions crParameterFieldDefinitions;
ParameterFieldDefinition crParameterFieldDefinition;
ParameterValues crParameterValues = new ParameterValues();
ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = textBox2.Text;
crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
crParameterFieldDefinition = crParameterFieldDefinitions["bankacid"];
crParameterValues = crParameterFieldDefinition.CurrentValues;
crParameterValues.Clear();
crParameterValues.Add(crParameterDiscreteValue);
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
crystalReportViewer4.ReportSource = cryRpt;
crystalReportViewer4.Refresh();
}
THANKS AGAIN
Sudhakar ChaudharyPosted Jan 16, 2013, 7:48 AM