Solved

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

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

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…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 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