Solved

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

Posted on 2006-06-29
3
589 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 500 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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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