I have written this code with the help of other programmers. This code works perfectly when running on Windows 7 but when I install the program on Windows XP the log-on fails. I have installed .Net Framework 4.0 and CRforVS_13_0_3 of Crystal Reports on the Windows XP machine.
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
label2.Text = Convert.ToString(BAssistencia.nroo);
ReportDocument segredo = new ReportDocument();
segredo.Load(@"C:/Relatorios/CrystalReport3.rpt");
ParameterField pf1 = new ParameterField();
ParameterFields pf1s = new ParameterFields();
ParameterDiscreteValue pdv = new ParameterDiscreteValue();
TableLogOnInfo tabla = new TableLogOnInfo();
TableLogOnInfos tablas = new TableLogOnInfos();
ConnectionInfo infocon = new ConnectionInfo();
Tables crtables;
infocon.ServerName = "server";
infocon.DatabaseName = "database";
infocon.UserID = "user";
infocon.Password = "password";
infocon.IntegratedSecurity = false;
crtables = segredo.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table crtable in crtables)
{
tabla = crtable.LogOnInfo;
tabla.ConnectionInfo = infocon;
crtable.ApplyLogOnInfo(tabla);
}
pf1.Name = "@pedido";
pdv.Value = label2.Text;
pf1.CurrentValues.Add(pdv);
pf1s.Add(pf1);
crystalReportViewer1.ParameterFieldInfo = pf1s;
crystalReportViewer1.ReportSource = segredo;
What am I doing wrong???
A few links, the first one are extension methods that I’ve written that I use with Crystal (on XP, Vista and 7 along with Server 2003, 2008 and they work there).
http://www.blakepell.com/Main/BlogEntry.aspx?EntryID=e2fcdcf9-312e-4911-8572-20178c94660b
The second one here has a different issue but in the end (before my rant) I have some info about gotchas swapping out connections at runtime.
The code provided above has worked for me in all of my environments. Now, in your case, you’ll also want to make sure that the XP box has access to the database server outside of Crystal also (no firewalls blocking, the server isn’t denying it access, no ACL’s in place that are stopping network routing, etc). Over the years I have found swapping connections out with Crystal to be very particular.