on 06-08-2015 10:08 AM
Hi,
I'm using VS 2010 with CR 13. I have an access 2013 DB (accdb) which is encrypted with a password. the following code works if I remove the password but I can't find anyway to set the password via code:
public void SetCrystalLoginOLEDB(ReportDocument report)
{
ConnectionInfo oConnectInfo = new ConnectionInfo();
//string dbpath = string.Concat(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"\db\db.accdb");
oConnectInfo.ServerName = Globals.DB;
oConnectInfo.DatabaseName = "";
oConnectInfo.UserID = "Admin";
oConnectInfo.Password = "";
//Set the logon credentials for all tables
SetCrystalTablesLogin(oConnectInfo, report.Database.Tables);
// Check for subreports
foreach (CrystalDecisions.CrystalReports.Engine.Section oSection in report.ReportDefinition.Sections)
{
foreach (CrystalDecisions.CrystalReports.Engine.ReportObject oRptObj in oSection.ReportObjects)
{
if (oRptObj.Kind == CrystalDecisions.Shared.ReportObjectKind.SubreportObject)
{
// This is a subreport so set the logon credentials for this report's tables
CrystalDecisions.CrystalReports.Engine.SubreportObject oSubRptObj = oRptObj as CrystalDecisions.CrystalReports.Engine.SubreportObject;
// Open the subreport
CrystalDecisions.CrystalReports.Engine.ReportDocument oSubRpt = oSubRptObj.OpenSubreport(oSubRptObj.SubreportName);
SetCrystalTablesLogin(oConnectInfo, oSubRpt.Database.Tables);
}
}
}
report.Refresh();
report.SetDatabaseLogon("Admin", "", Globals.DB, "");
report.VerifyDatabase();
report.Refresh();
}
private void SetCrystalTablesLogin(CrystalDecisions.Shared.ConnectionInfo oConnectInfo, Tables oTables)
{
foreach (CrystalDecisions.CrystalReports.Engine.Table oTable in oTables)
{
CrystalDecisions.Shared.TableLogOnInfo oLogonInfo = oTable.LogOnInfo;
oLogonInfo.ConnectionInfo = oConnectInfo;
oTable.ApplyLogOnInfo(oLogonInfo);
}
}
I've tried setting the ConnectionInfo password, but I realise this isn't the same as the Jet password.
Any help much appreciated.
Thanks,
Paul.
Hi Paul
First t hing I'd do is simplify; Use a report with no subreports. Then see KBA 1197214 - How to access a password protected MS-Access database?
You mat also want to see the following KBA which will actually write out the logon code for you:
1553921 - Is there a utility that would help in writing database logon code?
Again, use a report that has no subreports 1st. Once you have a simple report working, throw in a report with subreports. If the subreports start to cause problems, check that the same connection type is being used as in the main report.
- Ludek
Senior Support Engineer AGS Product Support, Global Support Center Canada
Follow me on Twitter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not if they are using an MDW - e.g.; Jet System Database PWD.
Now a way out may be for you to connect to the database programmatically outside of CR (e.g.; VB / C# APIs). Create a dataset off of the database and then pass the dataset to the report. In this way, you are controlling the logon to the database and the report has no idea there are any passwords, etc., etc
For more info on datasets see:
KBA 1511438 - How to use datasets to pass data to crystal reports
- Ludek
User | Count |
---|---|
78 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.