Solved

Print Crystal Report that uses a SQL stored procedure from C#, VS2008 -- log on problems

Posted on 2012-12-28
4
360 Views
Last Modified: 2013-01-09
Using the code show here I am trying to print a Crystal Report (2011) from C#, VS2008.  When I use these techniques on a table-based report, things work fine.  The current report is based on a stored procedure and I get "Unable to connect.  Incorrect log on parameters" at the PrintToPrinter command.  I have given the stored proceure explict execute permissions for the cyrstal user.  This was necessary to even see the s/p in the Crystal designer interface.

When I preview the report in the Crystal interface, everything works fine.  I do get the log on dialogue.  Part of that is the database name, of course, so I tried setting that in my code, too, but that didn't work.

What am I doing wrong?

                
                ReportDocument rpt1 = new ReportDocument();
                rpt1.Load(@"E:\LabelsfromSP.rpt");

                //log on
                //MessageBox.Show("Logging on");
                TableLogOnInfo crTLogOnInfo = new TableLogOnInfo();
                ConnectionInfo crConnInfo = new ConnectionInfo();
                Tables crTables;

                crConnInfo.ServerName = "_DATA_ODBC"; // this is an odbc connection
                crConnInfo.UserID = "crystal";
                crConnInfo.Password = "crystal";

                MessageBox.Show("here1");

                crTables = rpt1.Database.Tables;

                foreach (Table crTable in crTables)
                {
                    crTLogOnInfo = crTable.LogOnInfo;
                    crTLogOnInfo.ConnectionInfo = crConnInfo;
                    crTable.ApplyLogOnInfo(crTLogOnInfo);
                }

                MessageBox.Show("here2");

                rpt1.SetParameterValue("@ordType", "O");
                MessageBox.Show("here2a");
                rpt1.SetParameterValue("@ordNumber","00274945");

                MessageBox.Show("here2b");
                rpt1.PrintOptions.PrinterName = "PA1-2";

                //for (int nl = 1; nl <= numlabels; nl++)
                //{
                MessageBox.Show("here3");
                rpt1.PrintToPrinter(1, true, 0, 0);
                //}

                ////last label
                //if (remaining != 0)
                //{
                //    rpt1.SetParameterValue("QtyPer", remaining);
                //    rpt1.PrintToPrinter(1, true, 0, 0);
                //}

                //rpt1.PrintToPrinter(1, true, 0, 0);

                rpt1.Close();

Open in new window

0
Comment
Question by:g_johnson
  • 2
  • 2
4 Comments
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 38727919
Have you tried executing in debug mode and walking thorugh the code?

I am wondering if Crystal sees the SP as a table?

mlmcc
0
 
LVL 4

Author Comment

by:g_johnson
ID: 38728312
mlmcc -- yes, it's getting inside that loop.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 38728634
I don't know then.  I hav enever had to change it for a stored procedure.  It is possible that you can't since the SP is executed before the report is opened.

mlmcc
0
 
LVL 4

Author Comment

by:g_johnson
ID: 38759495
This turned out to be a so far unexplained problem with the ODBC connection.  A new connection fixed the issue.  These were great trouble shooting tips, though.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to truncate multiple tables from SQL Server Database using Stored procedure 8 49
ASP.NET 5 Templates 2 66
Error in JQuery 5 39
Code works but it's slow 24 44
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

11 Experts available now in Live!

Get 1:1 Help Now