469,610 Members | 1,775 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,610 developers. It's quick & easy.

Crystal Report log into two databases

Hello. I have been trying to log onto two databases at run time for a crystal report. I have tried both the crystal report viewer and the report document object viewer. I have no figured out a way to make it possible.

The code for the report document object viewer is below (with the server, password and user not included for both databases). It gives me an error saying that it cannot find the employee table (which is in the EmployeeTrack database).

Expand|Select|Wrap|Line Numbers
  1. protected void Page_Init(object sender, EventArgs e)
  2.     {
  3.         ConfigureCrystalReports();
  4.     }
  5.     private void ConfigureCrystalReports()
  6.     {
  7.         //string fieldUniqueID = Request.QueryString["UniqueID"];
  8.         //string fieldParID= Request.QueryString["ParID"];
  9.  
  10.        string fieldUniqueID = "100252";
  11.        string fieldParID = "1";
  12.  
  13.         ConnectionInfo connectionEmployee = new ConnectionInfo();
  14.         connectionEmployee.ServerName = "***************";
  15.         connectionEmployee.DatabaseName = "EmployeeTrack";
  16.         connectionEmployee.UserID = "***";
  17.         connectionEmployee.Password = "******";
  18.  
  19.         ConnectionInfo connectionPAR = new ConnectionInfo();
  20.         connectionPAR.ServerName = "********";
  21.         connectionPAR.DatabaseName = "PAR";
  22.         connectionPAR.UserID = "****";
  23.         connectionPAR.Password = "*****";
  24.  
  25.         reportSeparation = new ReportDocument();
  26.         string reportPath = Server.MapPath("Separation_Report_Local.rpt");
  27.         reportSeparation.Load(reportPath);
  28.  
  29.        SetDBLogonForReport(connectionEmployee, reportSeparation);
  30.        SetDBLogonForReport(connectionPAR, reportSeparation);
  31.  
  32.         SetCurrentValuesForParameterFieldUniqueID(reportSeparation, fieldUniqueID);
  33.         SetCurrentValuesForParameterFieldParID(reportSeparation, fieldParID);
  34.  
  35.         crystalReportViewer.ReportSource = reportSeparation;
  36.     }
  37.     private void SetCurrentValuesForParameterFieldUniqueID(ReportDocument reportDocument, String field)
  38.     {
  39.         ParameterValues currentParameterValues = new ParameterValues();
  40.         ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
  41.         parameterDiscreteValue.Value = field;
  42.         currentParameterValues.Add(parameterDiscreteValue);
  43.  
  44.         ParameterFieldDefinitions parameterFieldDefinitions = reportDocument.DataDefinition.ParameterFields;
  45.         ParameterFieldDefinition parameterFieldDefinition = parameterFieldDefinitions[PARAMETER_FIELD_UNIQUE];
  46.         parameterFieldDefinition.ApplyCurrentValues(currentParameterValues);
  47.     }
  48.     private void SetCurrentValuesForParameterFieldParID(ReportDocument reportDocument, String field)
  49.     {
  50.         ParameterValues currentParameterValues = new ParameterValues();
  51.         ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
  52.         parameterDiscreteValue.Value = field;
  53.         currentParameterValues.Add(parameterDiscreteValue);
  54.  
  55.         ParameterFieldDefinitions parameterFieldDefinitions = reportDocument.DataDefinition.ParameterFields;
  56.         ParameterFieldDefinition parameterFieldDefinition = parameterFieldDefinitions[PARAMETER_FIELD_PAR];
  57.         parameterFieldDefinition.ApplyCurrentValues(currentParameterValues);
  58.     }
  59.     private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)
  60.     {
  61.         Tables tables = reportDocument.Database.Tables;
  62.         foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
  63.         {
  64.             TableLogOnInfo tableLogonInfo = table.LogOnInfo;
  65.             tableLogonInfo.ConnectionInfo = connectionInfo;
  66.             table.ApplyLogOnInfo(tableLogonInfo);
  67.         }
  68.     }
  69. }
  70.  
  71.  
My code for crystal report viewer is below. I just have to fill in the password for one of the databases with the code below. The log in window for only one of the databases shows up.

Expand|Select|Wrap|Line Numbers
  1.  
  2. private const string PARAMETER_FIELD_UNIQUE = "UniqueID";
  3.     private const string PARAMETER_FIELD_PAR = "ParID";
  4.  
  5.  
  6.     protected void Page_Init(object sender, EventArgs e)
  7.     {
  8.         ConfigureCrystalReports();
  9.     }
  10.  
  11.     private void ConfigureCrystalReports()
  12.     {
  13.        string fieldUniqueID = Request.QueryString["UniqueID"];
  14.       string fieldParID = Request.QueryString["ParID"];
  15.  
  16.       //string fieldUniqueID = "100028";
  17.       // string fieldParID = "14";
  18.  
  19.         ConnectionInfo connectionEmployee = new ConnectionInfo();
  20.         connectionEmployee.ServerName = "********";
  21.         connectionEmployee.DatabaseName = "EmployeeTrack";
  22.         connectionEmployee.UserID = "****";
  23.         connectionEmployee.Password = "********";
  24.  
  25.         ConnectionInfo connectionPAR = new ConnectionInfo();
  26.         connectionPAR.ServerName = "***********";
  27.         connectionPAR.DatabaseName = "PAR";
  28.         connectionPAR.UserID = "*******";
  29.         connectionPAR.Password = "*********";
  30.  
  31.         string reportPath = Server.MapPath("PAR_Report_Local.rpt");
  32.         crystalReportViewer.ReportSource = reportPath;
  33.  
  34.         SetDBLogonForReport(connectionEmployee);
  35.         SetDBLogonForReport(connectionPAR);
  36.  
  37.  
  38.         SetCurrentValuesForParameterFieldUnique(parameterFields, fieldUniqueID);
  39.         SetCurrentValuesForParameterFieldPAR(parameterFields, fieldParID);
  40.  
  41.     }
  42.     private void SetCurrentValuesForParameterFieldUnique(ParameterFields parameterFields, String field)
  43.     {
  44.         ParameterValues currentParameterValues = new ParameterValues();
  45.  
  46.         ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
  47.         parameterDiscreteValue.Value = field;
  48.         currentParameterValues.Add(parameterDiscreteValue);
  49.  
  50.  
  51.         ParameterField parameterField = parameterFields[PARAMETER_FIELD_UNIQUE];
  52.         parameterField.CurrentValues = currentParameterValues;
  53.  
  54.     }
  55.     private void SetCurrentValuesForParameterFieldPAR(ParameterFields parameterFields, String field)
  56.     {
  57.         ParameterValues currentParameterValues = new ParameterValues();
  58.  
  59.         ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
  60.         parameterDiscreteValue.Value = field;
  61.         currentParameterValues.Add(parameterDiscreteValue);
  62.  
  63.  
  64.         ParameterField parameterField = parameterFields[PARAMETER_FIELD_PAR];
  65.         parameterField.CurrentValues = currentParameterValues;
  66.  
  67.     }
  68.  
  69.     private void SetDBLogonForReport(ConnectionInfo connectionInfo)
  70.     {
  71.         TableLogOnInfos tableLogOnInfos = crystalReportViewer.LogOnInfo;
  72.         foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
  73.         {
  74.             tableLogOnInfo.ConnectionInfo = connectionInfo;
  75.         }
  76.     }
  77. }
  78.  
  79.  
Any help would be greatly appreciated. Thanks.

-Michelle
Aug 7 '07 #1
0 1397

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

13 posts views Thread by kristoff plasun | last post: by
2 posts views Thread by Tim Burda | last post: by
3 posts views Thread by oscar | last post: by
2 posts views Thread by airkart | last post: by
reply views Thread by Atif | last post: by
2 posts views Thread by aldous scotch | last post: by
5 posts views Thread by jmar | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.