Example #1
0
        //public rpt()
        //{

        //}
        public void ConnectionInfo(ReportDocument _rpt)
        {
            //string[] strConnection = ConfigurationManager.ConnectionStrings[("csApp")].ConnectionString.Split(new char[] { ';' });
            _DBcon d = new _DBcon();

            string[] strConnection = d.getConnectionString().Split(new char[] { ';' });

            Database oCRDb     = _rpt.Database;
            Tables   oCRTables = oCRDb.Tables;

            CrystalDecisions.CrystalReports.Engine.Table oCRTable = default(CrystalDecisions.CrystalReports.Engine.Table);
            TableLogOnInfo oCRTableLogonInfo = default(CrystalDecisions.Shared.TableLogOnInfo);
            ConnectionInfo oCRConnectionInfo = new CrystalDecisions.Shared.ConnectionInfo();

            oCRConnectionInfo.ServerName   = strConnection[0].Split(new char[] { '=' }).GetValue(1).ToString();
            oCRConnectionInfo.DatabaseName = strConnection[1].Split(new char[] { '=' }).GetValue(1).ToString();
            oCRConnectionInfo.Password     = strConnection[4].Split(new char[] { '=' }).GetValue(1).ToString();
            oCRConnectionInfo.UserID       = strConnection[3].Split(new char[] { '=' }).GetValue(1).ToString();

            for (int i = 0; i < oCRTables.Count; i++)
            {
                oCRTable          = oCRTables[i];
                oCRTableLogonInfo = oCRTable.LogOnInfo;
                oCRTableLogonInfo.ConnectionInfo = oCRConnectionInfo;
                oCRTable.ApplyLogOnInfo(oCRTableLogonInfo);
                if (oCRTable.TestConnectivity())
                {
                    //' If there is a "." in the location then remove the
                    // ' beginning of the fully qualified location.
                    //' Example "dbo.northwind.customers" would become
                    //' "customers".
                    oCRTable.Location = oCRTable.Location.Substring(oCRTable.Location.LastIndexOf(".") + 1);
                }
            }

            for (int i = 0; i < _rpt.Subreports.Count; i++)
            {
                {
                    oCRDb     = _rpt.OpenSubreport(_rpt.Subreports[i].Name).Database;
                    oCRTables = oCRDb.Tables;
                    foreach (CrystalDecisions.CrystalReports.Engine.Table aTable in oCRTables)
                    {
                        oCRTableLogonInfo = aTable.LogOnInfo;
                        oCRTableLogonInfo.ConnectionInfo = oCRConnectionInfo;
                        aTable.ApplyLogOnInfo(oCRTableLogonInfo);
                        if (aTable.TestConnectivity())
                        {
                            //' If there is a "." in the location then remove the
                            // ' beginning of the fully qualified location.
                            //' Example "dbo.northwind.customers" would become
                            //' "customers".
                            aTable.Location = aTable.Location.Substring(aTable.Location.LastIndexOf(".") + 1);
                        }
                    }
                }
            }
            _rpt.Refresh();
        }
Example #2
0
        /// <summary>
        /// Assign a <see cref="ConnectionInfo"/> to a <see cref="CrystalDecisions.CrystalReports.Engine.Table"/> object
        /// </summary>
        /// <param name="table">Table to which the connection is to be assigned</param>
        /// <param name="connection">Connection to the database.</param>
        private static void AssignTableConnection(CrystalDecisions.CrystalReports.Engine.Table table, ConnectionInfo connection)
        {
            // Cache the logon info block
            TableLogOnInfo logOnInfo = table.LogOnInfo;

            // Set the connection
            logOnInfo.ConnectionInfo = connection;

            // Apply the connection to the table!
            table.ApplyLogOnInfo(logOnInfo);
        }
        public static void SetTableLogin(CrystalDecisions.CrystalReports.Engine.Table table)
        {
            CrystalDecisions.Shared.TableLogOnInfo tliCurrent = table.LogOnInfo;

            tliCurrent.ConnectionInfo.UserID   = builder.UserID;
            tliCurrent.ConnectionInfo.Password = builder.Password;
            if (builder.InitialCatalog != null)
            {
                tliCurrent.ConnectionInfo.DatabaseName = builder.InitialCatalog;
            }
            if (builder.DataSource != null)
            {
                tliCurrent.ConnectionInfo.ServerName = builder.DataSource;
            }
            table.ApplyLogOnInfo(tliCurrent);
        }
Example #4
0
        private void SetTableLogin(CrystalDecisions.CrystalReports.Engine.Table table)
        {
            CrystalDecisions.Shared.TableLogOnInfo tliCurrent = table.LogOnInfo;

            string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

            var builder = new SqlConnectionStringBuilder(connectionString);

            //var dataSource = builder.DataSource;

            tliCurrent.ConnectionInfo.UserID       = builder.UserID;         //"sa";
            tliCurrent.ConnectionInfo.Password     = builder.Password;       //"aziz123";
            tliCurrent.ConnectionInfo.DatabaseName = builder.InitialCatalog; //"Restaurant_DB"; //Database is not needed for Oracle & MS Access
            tliCurrent.ConnectionInfo.ServerName   = builder.DataSource;     //"NIMBLE\\SQL2K8";
            table.ApplyLogOnInfo(tliCurrent);
        }