Solved

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

Posted on 2012-12-28
4
364 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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

828 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