Link to home
Start Free TrialLog in
Avatar of GCCvanDorth
GCCvanDorth

asked on

PrintToPrinter gives LogOnException

Got a VB.NET windows application using a MsAccess database. Some of the reports (CR bundled version) have to be processed in batch mode. I use the PrintToPrinter method, it works fine on my development system but fails with a LogOnException on any other system. The same report can be perfectly previewed and printed (with interaction) by means of the CRViewer. I used the latest merge modules from crystal (BO) and set the connectionInfo for all tables (even in subreports).
What can be wrong?
Avatar of GCCvanDorth
GCCvanDorth

ASKER

Got it (about).

The whole stuff works if the database location in development is the same as the database location after deployment.
So if the database position will become "C:\progam files\myproject\database\mydatabase.mdb" you better create the report using this location too.
Nice? No, but at least something I can live with (as I know how my product is installed). So crystal ignores all the connectInfo somehow if you call PrintToPrinter (or ExportTo...).

Avatar of Mike McCracken
What code are you using?  It shouldn't work as you are statig so maybe there is a minor problem with the code.

mlmcc
I think you are missing setting the location property of the tables. If you miss that crystal disregards the connection chnages . Do it this way and it will work.
This code is written in c# so if you need, convert it to vb.net
Regards
Emre

internal static void SetConnection(ref ReportDocument report, string serverName, string databaseName)
{
  try
  {
  CrystalDecisions.Shared.TableLogOnInfo MyLogonInfo;
 foreach(CrystalDecisions.CrystalReports.Engine.Table MyTable in report.Database.Tables)
   {
                   
   MyLogonInfo = MyTable.LogOnInfo;
   if (MyTable.Name == "")
   {                             MyLogonInfo.ConnectionInfo.ServerName  = serverName;
MyLogonInfo.ConnectionInfo.DatabaseName = databaseName;
MyLogonInfo.ConnectionInfo.UserID = "";
MyLogonInfo.ConnectionInfo.Password= "";                              }
else
{              
MyLogonInfo.ConnectionInfo.ServerName  = serverName;
MyLogonInfo.ConnectionInfo.DatabaseName = databaseName;
//MyLogonInfo.ConnectionInfo.AllowCustomConnection  = true;
MyLogonInfo.ConnectionInfo.UserID  = "";
MyLogonInfo.ConnectionInfo.Password = "";                        
                               
}
MyTable.Location = MyTable.Location.SubstringMyTable.Location.LastIndexOf(".")+1);
MyTable.ApplyLogOnInfo(MyLogonInfo);          
                           
}                    
}
               catch( Exception logonInfoException )
               {
                    throw logonInfoException;
               }
          }
 
No, I didn't miss the location settings, I missed the CR9.0 service pack of October. It works fine with this package.
ASKER CERTIFIED SOLUTION
Avatar of ebolek
ebolek

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial