cancel
Showing results for 
Search instead for 
Did you mean: 

Setting Jet Database Password via c#

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi Ludek,

Thanks for the reply but this only shows how to set the report password using a ConnectionInfo object. I need to be able to set the Jet Database Password. This is the password I need to be able to set programmatically:

Thanks,

Paul.

former_member183750
Active Contributor
0 Kudos

Actually, we never supported Jet System Database PWD, so the KBA is for Jet Database PWD.

I'd still try with a simple, rpt and / or the code writing utility.

- Ludek

Former Member
0 Kudos

I have 30 reports already written and the client has decided to put a password on the MS Access DB. Are you saying there is no way to set this progammatically?

Thanks.

former_member183750
Active Contributor
0 Kudos

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

Answers (0)