PrintToPrinter gives LogOnException

Posted on 2004-11-06
Last Modified: 2007-12-19
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?
Question by:GCCvanDorth

    Author Comment

    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...).

    LVL 100

    Expert Comment

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

    LVL 10

    Expert Comment

    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

    internal static void SetConnection(ref ReportDocument report, string serverName, string databaseName)
      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= "";                              }
    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);
                   catch( Exception logonInfoException )
                        throw logonInfoException;

    Author Comment

    No, I didn't miss the location settings, I missed the CR9.0 service pack of October. It works fine with this package.
    LVL 10

    Accepted Solution

    Glad it is resolved

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
    Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now