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

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
?
594 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
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

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.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

926 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