Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2012-12-28
4
Medium Priority
?
375 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 101

Accepted Solution

by:
mlmcc earned 2000 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 101

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

824 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