Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

13 Experts available now in Live!

Get 1:1 Help Now