C# 如何使用动态连接水晶报表

C# 如何使用动态连接水晶报表,c#,wpf,crystal-reports,report,crystal-reports-2008,C#,Wpf,Crystal Reports,Report,Crystal Reports 2008,我在应用程序中使用动态连接 当我在应用程序中使用本地数据库时,我的报告没有任何问题 但当我使用另一个数据库(非本地)时,当我收到报告时,我的应用程序崩溃了 我使用c#和wpf 我该怎么办 try { ReportDocument rd = new ReportDocument(); ////////////////////// TableLogOnInfos crtableL

我在应用程序中使用动态连接

当我在应用程序中使用本地数据库时,我的报告没有任何问题

但当我使用另一个数据库(非本地)时,当我收到报告时,我的应用程序崩溃了

我使用c#和wpf

我该怎么办

 try
            {
                ReportDocument rd = new ReportDocument();
                //////////////////////
                TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
                TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
                ConnectionInfo crConnectionInfo = new ConnectionInfo();
                Tables CrTables;
                rd.Load(System.AppDomain.CurrentDomain.BaseDirectory + "report\\" + this.report_name);


                RegistryKey ConnectionKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\\forosh");
                string  server = (string)ConnectionKey.GetValue("ServerName");
                crConnectionInfo.ServerName = server;

                RegistryKey ConnectionKey2 = Registry.CurrentUser.CreateSubKey("SOFTWARE\\forosh");
                string db = (string)ConnectionKey2.GetValue("DbName");
                crConnectionInfo.DatabaseName = db;
                crConnectionInfo.IntegratedSecurity = true;

                CrTables = rd.Database.Tables;
                foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
                {
                    crtableLogoninfo = CrTable.LogOnInfo;
                    crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                    CrTable.ApplyLogOnInfo(crtableLogoninfo);
                }

                crv.ViewerCore.ReportSource = rd;
                crv.ViewerCore.RefreshReport();
                //////////////////////////////

                string path = System.AppDomain.CurrentDomain.BaseDirectory + "report\\" + this.report_name;
                rd.Load(path);
                rd.RecordSelectionFormula = this.GetFormula;

                switch (report_name)
                {

                    case "full.rpt":
                        {

                            break;
                        }
                    case "formul.rpt":
                        {

                            break;
                        }

                }


                crv.ViewerCore.ReportSource = rd;

            }
            catch {

            }
            }
 try
            {
                ReportDocument rd = new ReportDocument();
                //////////////////////
                TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
                TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
                ConnectionInfo crConnectionInfo = new ConnectionInfo();
                Tables CrTables;
                rd.Load(System.AppDomain.CurrentDomain.BaseDirectory + "report\\" + this.report_name);


                RegistryKey ConnectionKey = Registry.CurrentUser.CreateSubKey("SOFTWARE\\forosh");
                string  server = (string)ConnectionKey.GetValue("ServerName");
                crConnectionInfo.ServerName = server;

                RegistryKey ConnectionKey2 = Registry.CurrentUser.CreateSubKey("SOFTWARE\\forosh");
                string db = (string)ConnectionKey2.GetValue("DbName");
                crConnectionInfo.DatabaseName = db;
                crConnectionInfo.IntegratedSecurity = true;

                CrTables = rd.Database.Tables;
                foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
                {
                    crtableLogoninfo = CrTable.LogOnInfo;
                    crtableLogoninfo.ConnectionInfo = crConnectionInfo;
                    CrTable.ApplyLogOnInfo(crtableLogoninfo);
                }

                crv.ViewerCore.ReportSource = rd;
                crv.ViewerCore.RefreshReport();
                //////////////////////////////

                string path = System.AppDomain.CurrentDomain.BaseDirectory + "report\\" + this.report_name;
                rd.Load(path);
                rd.RecordSelectionFormula = this.GetFormula;

                switch (report_name)
                {

                    case "full.rpt":
                        {

                            break;
                        }
                    case "formul.rpt":
                        {

                            break;
                        }

                }


                crv.ViewerCore.ReportSource = rd;

            }
            catch {

            }
            }