Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQLConnection not working for Crystal Reports windows form - Getting a login dialog box during runtime

Posted on 2006-06-29
3
Medium Priority
?
593 Views
Last Modified: 2008-01-09
Two Issues

Issue 1.
Why does the Database Login dialog box pop up during runtime? The dialog box displays:

Table name: ADPFile
Server Name: Myserver
Database: MyDB
Login ID: MyUID
Password: <this is blank even though I provided it in the SQLConnection string>

Issue 2.
When I type in the password and click the Finish button, it display the report as a dump of the SQL Server View (ADPFile) NOT as the SELECT query that I want to pass.

Any help will be greatly appreciated. It is hard to find good documentation.  

IDE and Crystal Version - VS2003 Pro and Crystal Reports 9

Code Specifics -

private void Form4_Load(object sender, System.EventArgs e)
      {
                  
            ADPReport rpt = new ADPReport();
                        
            SqlConnection cn = new SqlConnection("Data Source=Myserver;Database=myDB;uid=MyUID;pwd=Hello");
                        
            SqlDataAdapter ADPda = new SqlDataAdapter("SELECT CEMPID, UTADPID, CEMPNAME, PAYRATE, COALESCE(EXPAMT,' ')AS EXPAMT, REGHRS, OTHRS,PAYTYPE FROM ADPFile WHERE (PAYTYPE = 1 AND EXPAMT IS NOT NULL) OR (PAYTYPE = 2) ORDER BY PAYTYPE, CEMPNAME", cn);
      
      DataSet ADPds = new DataSet();
      ADPda.Fill(ADPds, "Payroll");
                  
      rpt.SetDataSource(ADPds);
      crystalReportViewer1.ReportSource = rpt;
            
      }

Thanks,

Brad Swihart
Trigon IT
0
Comment
Question by:Trigon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
MyersA earned 1500 total points
ID: 17013965
Hi Trigon,

I also had the same problem, and I had trouble finding info on this on the Web. The problem (in my case, a webpage with CrystalReportViewer control - VS2005) is that you need to "tell" Crystal Reports what the username/password is.  Here's the code that I used:

private void Page_Init(object sender, EventArgs e)
{
  ConnectionInfo connectionInfo = new ConnectionInfo();
  connectionInfo.ServerName = "SERVER";
  connectionInfo.DatabaseName = "DBNAME";
  connectionInfo.UserID = "user";
  connectionInfo.Password = "pass";
  string reportPath = Server.MapPath("CrystalReport.rpt");
  CrystalReportViewer.ReportSource = reportPath;
  SetDBLogonForReport(connectionInfo);
}
private void SetDBLogonForReport(ConnectionInfo connectionInfo)
{
  TableLogOnInfos tableLogOnInfos = CrystalReportViewer.LogOnInfo;
  foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
  {
    tableLogOnInfo.ConnectionInfo = connectionInfo;
  }
}

You can find info here:
http://msdn2.microsoft.com/en-us/library/ms227471.aspx

VM
0
 

Author Comment

by:Trigon
ID: 17030820
Thanks for the quick reply. I'm out of the office and won't be back until July 6. I'll give the code a whirl and let you no the results by Friday.
0
 

Author Comment

by:Trigon
ID: 17054036
I accepted this solution with full credit because it led me to a lot of details that I needed to understand how VS2003 works with CR9.

However, I did not use the specific solution provided by MeyersA. Instead, I found a really concise solution in the SAMS Publishing book "Teach Yourself Visual Studio .NET 2003 in 21 Days" by Jason Beres. My code closely resembles his code in the chapter entitled "Day 18 Using Crystal Reports" and it works very well. I'm not sure I should copy the code here without violating copywrite laws so I'll suggest to anyone that needs a little more handholding to check this book out.

Thanks MeyersA for getting me to the final solution. I studied your code and followed the link you provided. Since I am building a windows form instead of a webform, I had to do additional searches. It is not easy to find good instructions but Beres' book really helped and got right to the point.

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

722 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