0

I wrote the following in Visual Studio 2010:

    label2.Text = Convert.ToString(BAssistencia.nroo);
    ReportDocument oRep = new ReportDocument();
    ParameterField campo = new ParameterField();
    ParameterFields campo2 = new ParameterFields();
    ParameterDiscreteValue Pdv = new ParameterDiscreteValue();

    campo.Name = "@pedido";
    Pdv.Value = label2.Text;
    campo.CurrentValues.Add(Pdv);
    campo2.Add(campo);
    crystalReportViewer1.ParameterFieldInfo = campo2;
    oRep.Load("C:/Relatorios/CrystalReport3.rpt");
    crystalReportViewer1.ReportSource = oRep;
    oRep.SetDatabaseLogon("sa","password","server","database");

The report opens fine on the computer with Visual Studio, but when I deploy, the application asks for the log again and again. What am I Doing wrong? Thanks in advance.

xelco52
  • 5,257
  • 4
  • 40
  • 56
alejandro carnero
  • 1,774
  • 7
  • 27
  • 43

2 Answers2

1

You have two options for solving this problem.

  1. Use a windows user account for accessing database More details are here

  2. Apply credentials to main reports and all subreports dynamically

Application runs slow when DB logging info is applied to each Crystal Reports Sections

http://www.daniweb.com/software-development/csharp/threads/214322/c-crystal-reports-changing-database-and-server-name

Community
  • 1
  • 1
Amal Dev
  • 1,938
  • 1
  • 14
  • 26
0

Can you try this code

ReportDocument rpt = new ReportDocument();
        rpt.Load(@"C:\CrystalReport1.rpt");

        ConnectionInfo crConnectionInfo = new ConnectionInfo();
        crConnectionInfo.ServerName = "SERVERNAME";
        crConnectionInfo.DatabaseName = "DATABASENAME";
        crConnectionInfo.UserID = "USERNAME";
        crConnectionInfo.Password = "PASSWORD";
        crConnectionInfo.IntegratedSecurity = false;

        TableLogOnInfos crTableLogonInfos = new TableLogOnInfos();
        TableLogOnInfo crTableLogonInfo = new TableLogOnInfo();
        Tables CrTables;
        CrTables = rpt.Database.Tables;

        foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in CrTables)
        {
            crTableLogonInfo = crTable.LogOnInfo;
            crTableLogonInfo.ConnectionInfo = crConnectionInfo;
            crTable.ApplyLogOnInfo(crTableLogonInfo);
        }
        crystalReportViewer1.ReportSource = rpt;
        crystalReportViewer1.Refresh();
Asif
  • 2,657
  • 19
  • 25
  • change it as per requirement it is working and will also work for you – Asif Jul 02 '12 at 11:27
  • thanks but from where come crTable??? i dont see where crtable is created. Crtables = rpt.database.tables exist but crtable?? I think this code may work . – alejandro carnero Jul 02 '12 at 14:21
  • @alejandro crTable is datatable of CrystalDecisions.CrystalReports.Engine.Table. just like foreach(DataRow dr in dt.Rows) which you often used in c#. you may use anyother name for crTable which you like. i have try this code and it is working fine. – Asif Jul 02 '12 at 18:42
  • Asif the code you have show works perfect in Windows 7, when i go to run on win XP again ask for logon. – alejandro carnero Jul 02 '12 at 20:38